From 30be8b5d845b9d5d18758f65c22ded6e8e53f435 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 20 Feb 2016 23:39:11 +0000 Subject: roundrect (20feb16) git-svn-id: svn://tug.org/texlive/trunk@39796 c570f23f-e606-0410-a88d-b1316a301751 --- .../source/metapost/roundrect/roundrect.dtx | 219 +++++++++++++-------- 1 file changed, 142 insertions(+), 77 deletions(-) (limited to 'Master/texmf-dist/source/metapost') diff --git a/Master/texmf-dist/source/metapost/roundrect/roundrect.dtx b/Master/texmf-dist/source/metapost/roundrect/roundrect.dtx index b63914371c8..20abd6dbbfb 100644 --- a/Master/texmf-dist/source/metapost/roundrect/roundrect.dtx +++ b/Master/texmf-dist/source/metapost/roundrect/roundrect.dtx @@ -37,6 +37,8 @@ \usepackage[everymp={input roundrect;},latex]{gmp} \usepackage{makeidx} \makeindex +\def\hanger{\parindent=0em\hangindent=2em\hangafter=1} +\def\thepar#1{\hbox{\parbox{0.5\linewidth}{\hanger\raggedright\ttfamily #1}}} \long\def\demonstrate#1#2{% \bigskip% \hrule% @@ -56,7 +58,7 @@ \end{document} % % \fi -% \title{The \texttt{roundrect} Macros, v2.1} +% \title{The \texttt{roundrect} Macros, v2.2} % \author{Donald P.\ Goodman III} % \date{\today} % @@ -126,8 +128,8 @@ % will draw it later: % % \demonstrate{% -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % roundrect(1in,2in)(rectangle); @@ -145,9 +147,9 @@ % less: % % \demonstrate{% -% \hbox{|rrborderrad(10pt);|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrborderrad(10pt);} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrborderrad(10pt); @@ -172,12 +174,12 @@ % using |:=| rather than as an argument in parentheses: % % \demonstrate{% -% \hbox{|rrtoplftborderrad := 20pt;|} -% \hbox{|rrbotlftborderrad := 40pt;|} -% \hbox{|rrtoprtborderrad := 10pt;|} -% \hbox{|rrbotrtborderrad := 60pt;|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrtoplftborderrad := 20pt;} +% \thepar{rrbotlftborderrad := 40pt;} +% \thepar{rrtoprtborderrad := 10pt;} +% \thepar{rrbotrtborderrad := 60pt;} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrtoplftborderrad := 20pt; @@ -195,10 +197,10 @@ % the border radius of the appropriate corners to |0pt|: % % \demonstrate{% -% \hbox{|rrtoplftborderrad := 0pt;|} -% \hbox{|rrtoprtborderrad := 0pt;|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrtoplftborderrad := 0pt;} +% \thepar{rrtoprtborderrad := 0pt;} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrtoplftborderrad := 0pt; @@ -225,10 +227,10 @@ % \DescribeMacro{rrbordercolor}|rrbordercolor()|. % % \demonstrate{% -% \hbox{|rrbordercolor(blue);|} -% \hbox{|rrinnercolor := red;|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrbordercolor(blue);} +% \thepar{rrinnercolor := red;} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrbordercolor(blue); @@ -254,13 +256,13 @@ % combine these in any way you like: % % \demonstrate{% -% \hbox{|rrbordercolor(blue);|} -% \hbox{|rrinnercolor := red;|} -% \hbox{|rrnotop := true;|} -% \hbox{|rrnobot := true;|} -% \hbox{|rrborderrad(0pt);|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrbordercolor(blue);} +% \thepar{rrinnercolor := red;} +% \thepar{rrnotop := true;} +% \thepar{rrnobot := true;} +% \thepar{rrborderrad(0pt);} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrbordercolor(blue); @@ -280,13 +282,13 @@ % from the others, using the commands you'd expect: % % \demonstrate{% -% \hbox{|rrtopbordercolor := blue;|} -% \hbox{|rrbotbordercolor := green;|} -% \hbox{|rrlftbordercolor := red;|} -% \hbox{|rrrtbordercolor := black;|} -% \hbox{|rrborderrad(20pt);|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrtopbordercolor := blue;} +% \thepar{rrbotbordercolor := green;} +% \thepar{rrlftbordercolor := red;} +% \thepar{rrrtbordercolor := black;} +% \thepar{rrborderrad(20pt);} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrtopbordercolor := blue; @@ -306,14 +308,14 @@ % constructs: % % \demonstrate{% -% \hbox{|rrbordercolor(black);|} -% \hbox{|rrbotbordercolor := green;|} -% \hbox{|rrinnercolor := red;|} -% \hbox{|rrborderrad(20pt);|} -% \hbox{|rrbotlftborderrad := 0pt;|} -% \hbox{|rrbotrtborderrad := 0pt;|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrbordercolor(black);} +% \thepar{rrbotbordercolor := green;} +% \thepar{rrinnercolor := red;} +% \thepar{rrborderrad(20pt);} +% \thepar{rrbotlftborderrad := 0pt;} +% \thepar{rrbotrtborderrad := 0pt;} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrbordercolor(black); @@ -334,9 +336,9 @@ % the border with, defined like any other \MP\ pen: % % \demonstrate{% -% \hbox{|rrborderpen(pensquare scaled 3);|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrborderpen(pensquare scaled 3);} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrborderpen(pensquare scaled 3); @@ -351,12 +353,12 @@ % border, as expected: % % \demonstrate{% -% \hbox{|rrbotlftborderrad := 0pt;|} -% \hbox{|rrbotrtborderrad := 0pt;|} -% \hbox{|rrbotbordercolor := green;|} -% \hbox{|rrbotborderpen := pensquare yscaled 6;|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrbotlftborderrad := 0pt;} +% \thepar{rrbotrtborderrad := 0pt;} +% \thepar{rrbotbordercolor := green;} +% \thepar{rrbotborderpen := pensquare yscaled 6;} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrbotlftborderrad := 0pt; @@ -380,9 +382,9 @@ % value which defaults to |false|: % % \demonstrate{% -% \hbox{|rrdropshadow := true;|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrdropshadow := true;} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrdropshadow := true; @@ -403,10 +405,10 @@ % can be set to any arbitrary \MP\ color: % % \demonstrate{% -% \hbox{|rrdropshadow := true;|} -% \hbox{|rrshadowcolor := blue;|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrdropshadow := true;} +% \thepar{rrshadowcolor := blue;} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrdropshadow := true; @@ -424,10 +426,12 @@ % in effect for the bottom left corner: % % \demonstrate{% -% \hbox{|rrdropshadow := true;|} -% \hbox{|rrshadowcolor := blue;|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrdropshadow := true;} +% \thepar{rrshadowcolor := blue;} +% \thepar{rrshadowx := -rrbotlftborderrad/4;} +% \thepar{rrshadowy := rrbotlftborderrad/4;} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrdropshadow := true; @@ -446,9 +450,9 @@ % configurable as everything else: % % \demonstrate{% -% \hbox{|rrbodytext := "Let's put some text into this rectangle and see if it typesets correctly!";|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrbodytext := "Let's put some text into this rectangle and see if it typesets correctly!";} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrbodytext := "Let's put some text into this rectangle and see if it typesets correctly!"; @@ -463,12 +467,12 @@ % \DescribeMacro{rrtextcolor}|rrtextcolor|: % % \demonstrate{% -% \hbox{|rrbodytext := "Text in a label";|} -% \hbox{|rrtextcolor := green;|} -% \hbox{|rrtextalign := "$\backslash$raggedleft";|} -% \hbox{|rrtextfont := "$\backslash$fontsize{17pt}{19pt}$\backslash$ selectfont$\backslash$ itshape";|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrbodytext := "Text in a label";} +% \thepar{rrtextcolor := green;} +% \thepar{rrtextalign := "$\backslash$raggedleft";} +% \thepar{rrtextfont := "$\backslash$fontsize{17pt}{19pt}$\backslash$ selectfont$\backslash$ itshape";} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrbodytext := "Text in a label"; @@ -494,10 +498,10 @@ % width can be set however you like: % % \demonstrate{% -% \hbox{|rrbodytext := "Let's put some text into this rectangle and see if it typesets correctly!";|} -% \hbox{|rrtextwd := 80pt;|} -% \hbox{|roundrect(1in,2in)(rectangle);|} -% \hbox{|draw rectangle;|} +% \thepar{rrbodytext := "Let's put some text into this rectangle and see if it typesets correctly!";} +% \thepar{rrtextwd := 80pt;} +% \thepar{roundrect(1in,2in)(rectangle);} +% \thepar{draw rectangle;} % }{% % \begin{mpost} % rrbodytext := "Let's put some text into this rectangle and see if it typesets correctly!"; @@ -507,12 +511,72 @@ % \end{mpost} % } % -% % Finally, to restore all these values to the default, use % the |rrrestorevals;| directive. This will clear % everything to default so you can have a completely % different |roundrect| in the same figure. % +% \section{Using External Packages in Text} +% +% Frequently, of course, the |rrtextfont| options will be +% either insufficient or overly cumbersome for your needs. +% For example, you might want \emph{all} the text in your +% labels to be in a different font; to match your main body +% font, for example. +% +% |roundrect| offers +% \DescribeMacro{rrusepackage}|rrusepackage| for this +% purpose. It is a string, designed specifically for the +% purpose of including arbitrary \LaTeX\ packages for +% typesetting text. For example, if your main body font is +% EB Garamond, the easiest way to get your text to match +% that is to ask \MP\ to use the |ebgaramond| package when +% it typesets: +% +% \demonstrate{% +% \thepar{rrusepackage := "$\backslash$usepackage\{ebgaramond\}";\hfill\break} +% \thepar{rrbodytext := "This is $\backslash$textsw\{EB\} Garamond, not Computer Modern.";\hfill\break} +% \thepar{roundrect(1in,2in)(rectangle);\hfill\break} +% \thepar{draw rectangle;\hfill\break} +% }{% +% \begin{mpost} +% rrbodytext := "This is \unexpanded{\textsw{EB}} Garamond, not Computer Modern."; +% rrusepackage := "\unexpanded{\usepackage{ebgaramond}}"; +% roundrect(1in,2in)(rectangle); +% draw rectangle; +% \end{mpost} +% } +% +% Notice that |rrusepackage := "\usepackage{ebgaramond}";| +% takes care of changing the body font \emph{and} of +% defining the |\textsw| environment (itself defined in +% |ebgaramond|), which we would otherwise have to do +% separately. +% +% To switch this back, simply reset the string to empty: +% +% \demonstrate{% +% \thepar{rrusepackage := "";\hfill\break} +% \thepar{rrbodytext := "This is Computer Modern, not EB Garamond.";\hfill\break} +% \thepar{roundrect(1in,2in)(rectangle);\hfill\break} +% \thepar{draw rectangle;\hfill\break} +% }{% +% \begin{mpost} +% rrbodytext := "This is Computer Modern, not EB Garamond."; +% rrusepackage := ""; +% roundrect(1in,2in)(rectangle); +% draw rectangle; +% \end{mpost} +% } +% +% Using color commands (e.g., from |color| or |xcolor|) will +% not throw errors, provided the appropriate package is +% included; however, it will not work. This seems to be an +% unavoidable consequence of the way that |TEX.mp| works; +% \TeX\ |\special| commands are destroyed in the process, +% and there isn't really a robust way to do it without this +% effect. +% % \section{Implementation} % % \begin{macrocode} @@ -529,6 +593,7 @@ string rrtextfont; rrtextfont := "\fontsize{10pt}{12pt}\selectfont "; color rrtextcolor; rrtextcolor := black; string rrbodytext; rrbodytext := ""; string rrtextalign; rrtextalign := "\centering"; +string rrusepackage; rrusepackage := ""; boolean rrnotop; rrnotop := false; boolean rrnobot; rrnobot := false; boolean rrnolft; rrnolft := false; @@ -581,7 +646,7 @@ def rrrestorevals = rrshadowy := -rrbotrtborderrad/4; enddef; def roundrect(expr rrht, rrwd)(suffix name) = - TEXPRE("%&latex" & char(10) & "\documentclass{article}\begin{document}"); + TEXPRE("%&latex" & char(10) & "\documentclass{article}" & rrusepackage & "\begin{document}"); TEXPOST("\end{document}"); if (rrtextwd = 0): rrtextwd := rrwd - 12pt; -- cgit v1.2.3