diff --git a/.github/workflows/context.yml b/.github/workflows/context.yml index afb6157..9e85dc1 100644 --- a/.github/workflows/context.yml +++ b/.github/workflows/context.yml @@ -27,12 +27,12 @@ jobs: working-directory: lettrines - name: Build English pdf - run: context --nonstopmode byrne_context.tex + run: lualatex -interaction=nonstopmode byrne-en-latex.tex - name: Build Russian pdf - run: context --nonstopmode byrne_ru_context.tex + run: lualatex -interaction=nonstopmode byrne-ru-latex.tex - uses: actions/upload-artifact@v3 with: name: pdfs - path: byrne*context.pdf + path: byrne*latex.pdf diff --git a/byrne-book.cls b/byrne-book.cls index 7d76141..e6a18b9 100644 --- a/byrne-book.cls +++ b/byrne-book.cls @@ -39,6 +39,10 @@ \def\mpPre{u:=1cm;} +\DeclareOption{letters}{\def\mpPre{u:=1cm; textLabels := true;}} + +\ProcessOptions\relax + \newdimen\LettrineSize \newcount\LettrineScale \newdimen\LettrinePadding diff --git a/byrne-en-latex.tex b/byrne-en-latex.tex index f340780..c3f9974 100644 --- a/byrne-en-latex.tex +++ b/byrne-en-latex.tex @@ -1,4 +1,4 @@ -\input latex-preamble.tex +\documentclass{byrne-book} \usepackage[british]{babel} @@ -89,7 +89,7 @@ {\large github.com/jemmybutton} \vskip 0.25\baselineskip -{\Large 2024 ed.\,0.8a} +{\Large 2024 ed.\,0.8-latex-alpha} \vskip \baselineskip \ccbysa diff --git a/byrne-ru-latex.tex b/byrne-ru-latex.tex index 66c750f..de03efe 100644 --- a/byrne-ru-latex.tex +++ b/byrne-ru-latex.tex @@ -1,4 +1,4 @@ -\documentclass{byrne-book} +\documentclass[letters]{byrne-book} \usepackage[russian]{babel} @@ -89,7 +89,7 @@ {\large github.com/jemmybutton} \vskip 0.25\baselineskip -{\Large 2024 ed.\,0.8a} +{\Large 2024 ed.\,0.8-latex-a} \vskip \baselineskip \ccbysa @@ -12862,7 +12862,7 @@ \chapter*{Определения} draw byLabelsOnPolygon(G, K, H)(ALL_LABELS, 0); } \drawCurrentPictureInMargin -\problem[2]{П}{остроить}{прямолинейную фигуру, подобную данной \hskip -11pt \drawPolygon[middle][triangleABC]{ABC} \hskip -9pt и~равную другой данной \drawPolygon[middle][polygonD]{D}.} +\problem[2]{П}{остроить}{прямолинейную фигуру, подобную данной \drawPolygon[middle][triangleABC]{ABC} и~равную другой данной \drawPolygon[middle][polygonD]{D}.} \begin{center} На \drawUnitLine{BC} опишем $\drawPolygon[middle][polygonBCEL]{BCEL} = \triangleABC$\\ diff --git a/byrne.sty b/byrne.sty new file mode 100644 index 0000000..3881af5 --- /dev/null +++ b/byrne.sty @@ -0,0 +1,309 @@ +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{byrne}[2023/04/22 Byrne] + +\RequirePackage{xparse} +\RequirePackage{ifmtarg} +\RequirePackage{luamplib} % version v2.22.0 is required +\mplibsetformat{metafun} + +\mplibglobaltextext{enable} +\newcount\mpInst +\mpInst = 0 +\newcount\mpLastInst +\mpLastInst = 0 + +\def\mpPre{} +\def\mpPost{} + +% point label style +\def\pointlabel#1{\textsf{#1}} + +\newif\ifCreateNewInstanceForPicture +\CreateNewInstanceForPicturetrue + +\directlua{ +function byFormatImageName(s) + local resultingName = s:gsub ("[,| |/|0-9]","") + resultingName = resultingName:gsub ("-","minus") + tex.print("instanceOffspringPicture"..resultingName) +end +} + +\def\formatImageName#1{\directlua{byFormatImageName("#1")}} + +\def\UseNextPicture{% + \global\advance \mpInst by 1% + \global\def\currentInstance{byInstance\the\mpInst}% +} + +\def\UsePreviousPicture{% + \global\advance \mpInst by -1% + \global\def\currentInstance{byInstance\the\mpInst}% +} + +\def\UseLastPicture{% + \global\mpInst = \mpLastInst% + \global\def\currentInstance{byInstance\the\mpInst}% +} + +\DeclareDocumentCommand{\defineNewPicture}{o o m}{% + \IfNoValueTF{#1}% + {\global\def\sfA{1/3}}% + {\global\def\sfA{#1}}% + \IfNoValueTF{#2}% + {\global\def\sfB{defaultScaleFactor}}% + {\global\def\sfB{#2}}% + \ifCreateNewInstanceForPicture% + \global\advance \mpLastInst by 1% + \UseLastPicture + %\global\def\currentInstance{byInstance\the\mpLastInst}% + \fi% + \setbox0\vbox{% + \everymplib[\currentInstance]{beginfig(0);}% + \everyendmplib[\currentInstance]{endfig;}% + \begin{mplibcode}[\currentInstance]% + picture instanceMainPicture; + input byrne; + \mpPre + instanceMainPicture := image( + startMainPictureMode; + projectionAngle := (0, 0, 0); + linecap := butt; + scaleFactor := \sfB; + #3 + scaleFactor := \sfA; + generateAngleSynonyms; + generateLineSynonyms; + stopMainPictureMode; + ); + \mpPost + \end{mplibcode}% + }% +} + +\def\drawImageFromCurrentInstance#1{ + \begin{mplibcode}[\currentInstance]% + draw #1; + \end{mplibcode}% +} + +% When larger picture is defined, we can visualize its parts with \drawFromCurrentPicture +% First (optional) argument is for picture's vertical alignment relative to the string +% Currently only `middle' and anything other (for `top') is working +% Second (optional) argument is for picture's name for future reuse +% If picture with the same name exists, it's not defined again. +% Third argument is MP code for picture itself. +% To actually define an inline picture \defineFromCurrentPicture is called. +% The latter can also be called separately, which can be convenient +% if one wants to define multiple inline pictures in one place. +% Whenever everything is defined, \drawDefinedPicture macro is called for + +\def\defineFromCurrentPicture#1#2#3{% + \begin{mplibcode}[\currentInstance]% + picture \formatImageName{#2}; + \formatImageName{#2} = image( + startOffspringPictureMode; + linecap := butt; + #3 + stopOffspringPictureMode; + ); + \end{mplibcode}% +\global\def\lastPict{#2}% +\global\expandafter\edef\csname\lastPict\endcsname{{\noexpand\drawDefinedPicture{\expandafter\lastPict}{\expandafter#1}}}% +\global\expandafter\edef\csname instanceNameFor\lastPict\endcsname{{\currentInstance}}% +} + +\DeclareDocumentCommand{\drawFromCurrentPicture}{o o m}{% + \IfNoValueTF{#1}% + {\global\def\currentInlinePicturePlacement{middle}}% + {\global\def\currentInlinePicturePlacement{#1}}% + \IfNoValueTF{#2}% + {\defineFromCurrentPicture{\currentInlinePicturePlacement}{lastPicture}{#3}}% + {\expandafter\ifx\csname instanceNameFor#2\endcsname\currentInstance% + \global\def\lastPict{#2}% + + \else% + \defineFromCurrentPicture{\currentInlinePicturePlacement}{#2}{#3}% + \fi}% + \csname\lastPict\endcsname% +} + +% \drawDefinedPicture draws defined and named picture, aligned as needed and, +% possibly, with margins modified with \offsetPicture (i. e., if we want picture to act as if it's less tall that it actually is, +% we put some value as its first argument, if we want picture to be less deep, we use second argument, and place picture +% itself as third). + +\newdimen\pictOffsetTop +\newdimen\pictOffsetBottom +\newdimen\pictVMargins + +\pictOffsetTop=0pt +\pictOffsetBottom=0pt +\pictVMargins=2pt + +\newif\ifRemoveMarginsFromSmallerPics +\RemoveMarginsFromSmallerPicstrue + +\def\offsetPicture#1#2#3{{\pictOffsetTop=#1\pictOffsetBottom=#2#3\pictOffsetTop=0pt\pictOffsetBottom=0pt}} + +\newdimen\midht +\newdimen\middp +\def\drawDefinedPicture#1#2{% + \setbox0\vbox{\drawImageFromCurrentInstance{\formatImageName{#1}}}% + \ifRemoveMarginsFromSmallerPics\ifdim\ht0<\baselineskip\advance\pictOffsetTop by 1pt\advance\pictOffsetBottom by 1pt\fi\fi% + \setbox0\vbox{\vskip\pictVMargins\vskip-\pictOffsetTop\box0\vskip\pictVMargins\vskip-\pictOffsetBottom}% + \def\tmpmiddle{middle}% + \def\tmpalignment{#2}% + \ifx\tmpalignment\tmpmiddle% + \middp=0.5\ht0 + \midht=0.5\ht0 + \advance\middp by -3pt + \advance\midht by 3pt + \else% + \middp=0pt + \midht=\ht0 + \advance\middp by 3pt + \advance\midht by -3pt + \fi% + \advance\middp by 0.5\pictOffsetTop + \advance\midht by -0.5\pictOffsetTop + \advance\middp by -0.5\pictOffsetBottom + \advance\midht by 0.5\pictOffsetBottom + \dp0=\middp + \ht0=\midht + \nobreak\hskip0pt\nobreak\,\nobreak\box0\,% +} + +% Some convenient shorthand macros for commonly used derivations of definition picture are defined below + +\def\drawCurrentPicture{\drawImageFromCurrentInstance{instanceMainPicture}} + + +\DeclareDocumentCommand{\drawUnitLine}{o m}{% + \IfNoValueTF{#1}% + {\drawFromCurrentPicture[middle][uline#2]{startAutoLabeling;draw byNamedCompoundLine(1cm, 0)(#2);stopAutoLabeling;}}% + {\drawFromCurrentPicture[middle][uline#2#1]{startAutoLabeling;draw byNamedCompoundLine(#1, 0)(#2);stopAutoLabeling;}}% +} + +\def\drawProportionalLine#1{\drawFromCurrentPicture[middle][pline#1]{startAutoLabeling;draw byNamedCompoundLine(1cm, 1)(#1);stopAutoLabeling;}} + +\DeclareDocumentCommand{\drawSizedLine}{o m}{% + \IfNoValueTF{#1}% + {\drawFromCurrentPicture[middle][sline#2]{startAutoLabeling;draw byNamedCompoundLine(2cm, 2)(#2);stopAutoLabeling;}}% + {\drawFromCurrentPicture[middle][sline#2#1]{startAutoLabeling;draw byNamedCompoundLine(#1, 2)(#2);stopAutoLabeling;}}% +} + +\DeclareDocumentCommand{\drawUnitRay}{o m}{% + \IfNoValueTF{#1}% + {\drawFromCurrentPicture[middle][uray#2]{startAutoLabeling;draw byNamedCompoundRay(1cm, 0)(#2);stopAutoLabeling;}}% + {\drawFromCurrentPicture[middle][uray#2#1]{startAutoLabeling;draw byNamedCompoundRay(#1, 0)(#2);stopAutoLabeling;}}% +} + +\def\drawProportionalRay#1{\drawFromCurrentPicture[middle][pray#1]{startAutoLabeling;draw byNamedCompoundRay(1cm, 1)(#1);stopAutoLabeling;}} + +\DeclareDocumentCommand{\drawSizedRay}{o m}{% + \IfNoValueTF{#1}% + {\drawFromCurrentPicture[middle][sray#2]{startAutoLabeling;draw byNamedCompoundRay(2cm, 2)(#2);stopAutoLabeling;}}% + {\drawFromCurrentPicture[middle][sray#2#1]{startAutoLabeling;draw byNamedCompoundRay(#1, 2)(#2);stopAutoLabeling;}}% +} + +\def\drawProportionalIndLine#1{\drawFromCurrentPicture[middle][lineindprop#1]{startAutoLabeling;draw byNamedCompoundIndLine(1cm, 1)(#1);stopAutoLabeling;}} + +\DeclareDocumentCommand{\drawUnitIndLine}{o m}{% + \IfNoValueTF{#1}% + {\drawFromCurrentPicture[middle][lineindsized#2]{startAutoLabeling;draw byNamedCompoundIndLine(2cm, 2)(#2);stopAutoLabeling;}}% + {\drawFromCurrentPicture[middle][lineindsized#2#1]{startAutoLabeling;draw byNamedCompoundIndLine(#1, 2)(#2);stopAutoLabeling;}}% +} + +\def\drawRightAngle{% +\drawFromCurrentPicture[middle][onerightangle]{draw rightAngle;}} + +\def\drawTwoRightAngles{% +\drawFromCurrentPicture[middle][tworightangles]{draw twoRightAngles;}} + +\def\drawAngle#1{\drawFromCurrentPicture[middle][angle#1]{startAutoLabeling;draw byNamedAngleWithDummySides(#1);stopAutoLabeling;}} + +\def\drawAngleWithSides#1{\drawFromCurrentPicture[middle][anglewithsides#1]{startAutoLabeling;draw byNamedAngleSides(#1)();stopAutoLabeling;}} + +\DeclareDocumentCommand{\drawPolygon}{o o m}{% + \IfNoValueTF{#1}% + {\global\def\plal{middle}}% + {\global\def\plal{#1}}% + \IfNoValueTF{#2}% + {\drawFromCurrentPicture[\plal][polygon#3]{startAutoLabeling;draw byNamedPolygon(#3);stopAutoLabeling;}}% + {\drawFromCurrentPicture[\plal][#2]{startAutoLabeling;draw byNamedPolygon(#3);stopAutoLabeling;}}% +} + +\DeclareDocumentCommand{\drawCircle}{o o m}{% + \IfNoValueTF{#1}% + {\global\def\plal{middle}}% + {\global\def\plal{#1}}% + \IfNoValueTF{#2}% + {\drawFromCurrentPicture[\plal][circle#3]{startAutoLabeling;draw byNamedCircle(#3);stopAutoLabeling;}}% + {\drawFromCurrentPicture[\plal][circle#3]{ + startAutoLabeling; + startTempScale(#2); + draw byNamedCircle(#3); + stopTempScale; + stopAutoLabeling; + }}% +} + +\DeclareDocumentCommand{\drawArc}{o o m}{% + \IfNoValueTF{#1}% + {\global\def\plal{middle}}% + {\global\def\plal{#1}}% + \IfNoValueTF{#2}% + {\drawFromCurrentPicture[\plal][arc#3]{startAutoLabeling;draw byNamedArcSeq(0)(#3);stopAutoLabeling;}}% + {\drawFromCurrentPicture[\plal][arc#3]{ + startAutoLabeling; + startTempScale(#2); + draw byNamedArcSeq(0)(#3); + stopTempScale; + stopAutoLabeling; + }}% +} + +\DeclareDocumentCommand{\drawLine}{o o m}{% + \IfNoValueTF{#1}% + {\global\def\plal{middle}}% + {\global\def\plal{#1}}% + \IfNoValueTF{#2}% + {\drawFromCurrentPicture[\plal][line#3]{startAutoLabeling;draw byNamedLineSeq(0)(#3);stopAutoLabeling;}}% + {\drawFromCurrentPicture[\plal][#2]{startAutoLabeling;draw byNamedLineSeq(0)(#3);stopAutoLabeling;}}% +} + +\def\drawPointM#1{\drawFromCurrentPicture[middle][pointm#1]{startAutoLabeling; draw byNamedPointMark(#1); stopAutoLabeling;}} + +\DeclareDocumentCommand{\drawPointL}{o o m}{% + \IfNoValueTF{#1}% + {\global\def\plal{middle}}% + {\global\def\plal{#1}}% + \IfNoValueTF{#2}% + {\drawFromCurrentPicture[\plal][pointl#3]{startAutoLabeling; draw byNamedPointLines(#3,""); stopAutoLabeling;}}% + {\drawFromCurrentPicture[\plal][pointl#3Minus#2]{startAutoLabeling; draw byNamedPointLines(#3,"#2"); stopAutoLabeling;}}% +} + +\DeclareDocumentCommand{\drawPoint}{o o m}{% + \IfNoValueTF{#1}% + {\global\def\plal{middle}}% + {\global\def\plal{#1}}% + \IfNoValueTF{#2}% + {\drawFromCurrentPicture[\plal][point#3]{ + startAutoLabeling; draw byNamedPointLines(#3,""); stopAutoLabeling; + draw byNamedPointMark(#3); + }}% + {\drawFromCurrentPicture[\plal][point#3Minus#2]{ + startAutoLabeling; draw byNamedPointLines(#3,"#2"); stopAutoLabeling; + draw byNamedPointMark(#3); + }}% +} + +\DeclareDocumentCommand{\drawMagnitude}{o o m}{% + \IfNoValueTF{#1}% + {\global\def\plal{middle}}% + {\global\def\plal{#1}}% + \IfNoValueTF{#2}% + {\drawFromCurrentPicture[\plal][magnitude#3]{startAutoLabeling;draw byNamedMagnitude(0)(#3);stopAutoLabeling;}}% + {\drawFromCurrentPicture[\plal][magnitude#2#3]{startAutoLabeling;draw byNamedMagnitude(#2)(#3);stopAutoLabeling;}}% +} \ No newline at end of file