Debian Codegraph @

texmf-dist/doc/latex/pdftoolbox/Documentation/pdfgraphics-docs.tex

raw
1 The pdfGraphics section of the \pdftoolbox{} toolbox is for pdf-specific graphics macros.
2 You can use it to create colorful documents with illustrations, etc.
3
4 \subsection{Colors}
5
6 In {\tt pdfGraphics/colors.tex}, \pdftoolbox{} provides macros for coloring text and areas of your document.
7
8 \macroexp{\color <color space>{<code>}/cr\color {<name>}}
9 Switches the color of the document.
10 In its first form, {\it color space} corresponds to either {\tt rgb} or {\tt cmyk}, and {\it code} is either an rgb or cmyk code.
11 In its second form, if {\it name} is a predefined color name (see \gotomacro\definecolor), the color is switched to it.
12 \emacroexp
13
14 \macroexp{\localcolor <color space>{<code>}{<text>}/cr\localcolor {<name>}{<text>}}
15 Switches the color of {\it text}, according to the options provided (see \gotomacro\color).
16 \emacroexp
17
18 \macroexp{\definecolor {<name>}{<color space>}{<code>}}
19 Defines a color of name {\it name} whose space is {\it color space} (either {\tt rgb} or {\tt cmyk}) of code {\it code} (either an rgb or cmyk code).
20 \emacroexp
21
22 \macroexp{\letcolor {<new name>}{<name>}}
23 Defines a color of name {\it new name} to be equal to the existing color of name {\it name}.
24 \emacroexp
25
26 \macroexp{\definecolormacro {<name>}{<color space>}{<code>}}
27 Calls \gotomacro\definecolor, and also defines a macro of name {\it name} which is equivalent to \inlinecode|\localcolor <color space>{<code>}{#1}|.
28
29 The following colors are defined:
30
31 \centerline{\red{red} \blue{blue} \green{green} \yellow{yellow} \orange{orange} \purple{purple} \highlightbox{black}{\white{white}} \black{black} \darkgreen{darkgreen} \grey{grey}}
32 \emacroexp
33
34 \macroexp{\highlightbox <color space>{<code>}{<material>}/cr
35 \highlightbox {<name>}{<material>}}
36 Colors the background of the material {\it material} according to the color provided.
37 For example \inlinecode|\highlightbox {red}{pdfToolbox}| will yield \highlightbox{red}{pdfToolbox}.
38 \emacroexp
39
40 \macroexp{\coloredbox <color space>{<code>}{<material>}/cr
41 \coloredbox {<name>}{<material>}}
42 Like \gotomacro\highlightbox{} but adds a buffer of space around {\it material} in accordance with \macro\bufferwidth\anchormacro\bufferwidth{} and \macro\bufferheight\anchormacro\bufferheight.
43 For example the following code: \inlinecode|\coloredbox {red}{pdfToolbox}|; will yield \coloredbox{red}{pdfToolbox}.
44 \emacroexp
45
46 \macroexp{\framecoloredbox <color space>{<code>}{<material>}/cr
47 \framecoloredbox {<name>}{<material>}}
48 Like \gotomacro\coloredbox{} but adds a frame around {\it material} of width \macro\framewidth.
49 For example \inlinecode|\framecoloredbox {red}{pdfToolbox}| will yield \framecoloredbox{red}{pdfToolbox}.
50 \emacroexp
51
52 \macroexp{\framebox {<material>}}
53 Adds a frame around {\it material} with a buffer of \macro\bufferwidth{} and \macro\bufferheight{} of width \macro\framewidth.
54 \emacroexp
55
56 \macroexp{\curvedcolorbox {<stroke color>}{<bg color>}{<material>}{<curve control>}}
57 Creates a curved color framed box around {\it material} with frame color {\it stroke color} and background color {\it bg color} (which may be names or of the form \inlinecode|<color space>{<code>}|.
58 The curve's stroke width is determined by \macro\curvewidth, and the buffer around the material is determined by \macro\curvebuffer.
59
60 {\it control} is a sequence of $8$ symbols of the form \getmacrousageB{<bline><bldot><lline><tldot><tline><trdot><rline><brdot>} where each $\langle{\tt X\it dot}\rangle$ corresponds to whether or not a corner is curved or not
61 ({\tt bl} for bottom left, {\tt tl} for top left, etc.), and each $\langle{\tt X\it line}\rangle$ corresponds to whether or not a border is drawn or not ({\tt b} for bottom, {\tt l} for left, etc.).
62 For a corner, {\tt.} corresponds to a curve and {\tt X} for a right corner.
63 For a border, {\tt-} corresponds to drawing the line and \inlinecode|_| to not.
64
65 A shadow of color \macro\boxshadowcolor{} is added to to the box, at an x and y offset of \macro\shadowxoff{} and \macro\shadowyoff{} respectively.
66
67 So for example:
68
69 \displaycode{%
70 \curvedcolorbox{blue}{red}{\color{white}pdfToolbox}{-.-.-.-.}&\cr
71 \curvedcolorbox{blue}{red}{\color{white}pdfToolbox}{-X-.-.-.}&\cr
72 \curvedcolorbox{blue}{red}{\color{white}pdfToolbox}{-.-X-.-.}&\cr
73 \curvedcolorbox{blue}{red}{\color{white}pdfToolbox}{-.-.-X-.}&\cr
74 \curvedcolorbox{blue}{red}{\color{white}pdfToolbox}{-.-.-.-X}&\cr
75 \curvedcolorbox{blue}{red}{\color{white}pdfToolbox}{_X-X_X-X}&\cr
76 \curvedcolorbox{blue}{red}{\color{white}pdfToolbox}{_._._._.}&\cr
77 \curvedcolorbox{blue}{red}{\color{white}pdfToolbox}{-X_X-X_X}&}
78 \emacroexp
79
80 \macroexp{\fakebold {<material>}}
81 Bolds the material {\it material} (essentially just thickening the stroke width according to \macro\fakeboldwidth).
82 \emacroexp
83
84 \macroexp{\flip {<material>}}
85 \quitvmode\flip{flips} {\it material} about its vertical axis.
86 \emacroexp
87
88 \subsection{Colorboxes}
89
90 In {\tt pdfGraphics/colorboxes.tex}, \pdftoolbox{} provides macros for pretty printing textboxes (ppboxes).
91 These are simply colored textboxes which can split across pages.
92 There are two kinds of pretty textboxes: {\tt ppbox}es and {\tt linedppbox}es.
93
94 \macroexp{\bppbox {<bg color>}{<stroke color>}{<fg color>}[<curve control>] ... \eppbox}
95 This creates a {\tt ppbox}, which is just a wrapper around \gotomacro\curvedcolorbox.
96 \emacroexp
97
98 \macroexp{\blinedppbox {<bg color>}{<stroke color>}{<fg color>} ... \elinedppbox}
99 This creates a colored textbox with a rule down the left side.
100 For example:
101
102 \blinedppbox{red}{black}{white}
103 This is a {\tt linedppbox} with a red background, black stroke, and white text.
104 \elinedppbox
105
106 The width of the rule is determined by \macro\pprulewd, the vertical buffer within the box (around the text) is determined by \macro\pprulevbuf, and the horizontal buffer on the left is \macro\pprulehbuf.
107 \emacroexp
108
109 \subsection{Illustrating}
110
111 In {\tt pdfGraphics/pdfdraw.tex}, \pdftoolbox{} provides macros for creating illustrations.
112
113 \bwarning
114 This feature scares me.
115 Its implementation is a mess and I am scared to change it; but I will need to at some point.
116 \eppbox
117
118 \macroexp{\bdrawing...\edrawing}
119 Begin a drawing environment.
120 The drawing environment is a plane as large as the drawings within it.
121 $(0,0)$ corresponds to the bottom left corner.
122 \emacroexp
123
124 \macroexp{\addnode {<text>}{<x>}{<y>}{<name>}}
125 Creates a node by the name of {\it name} with text {\it text} at coordinate $(x,y)$.
126 You can access the following values (called node-relative coordinates): {\tt<name>.left}, {\tt<name>.top}, {\tt<name>.right}, {\tt<name>.bottom}, {\tt<name>.xcenter}, {\tt<name>.ycenter}.
127 \emacroexp
128
129 \macroexp{\drawpath {<start x>}{<start y>}{<end x>}{<end y>}{<x off>}{<y off>}{<start cap>}{<end cap>}{<color>}}\hfill\break
130 Draws a line from $(\hbox{\it start x},\hbox{\it start y})$ to $(\hbox{\it end x},\hbox{\it end y})$.
131 This is offset by {\it off x} on the $x$-axis and {\it off y} on the $y$-axis (these are dimensions).
132 {\it start cap} is the linecap used at the starting point, and {\it end cap} is the linecap used at the end point (see \gotomacro\definelinecap).
133 The line is drawn in the color {\it color}.
134
135 The coordinates may be numeric values or node-relative coordinates (see \gotomacro\addnode).
136 \emacroexp
137
138 \macroexp{\drawbezier {<start x>}{<start y>}{<end x>}{<end y>}{<off>}{<curvature>}{<start cap>}{<end cap>}{<color>}}\hfill\break
139 Draws a curve from $(\hbox{\it start x},\hbox{\it start y})$ to $(\hbox{\it end x},\hbox{\it end y})$ with curvature {\it curvature}.
140 This is offset by {\it off}, which must be a pair of the form \inlinecode|{<x off>}{<y off>}| corresponding to the $x$-axis offset and $y$-axis offset respectively (dimensions).
141 {\it start cap} is the linecap used at the starting point, and {\it end cap} is the linecap used at the end point (see \gotomacro\definelinecap).
142 The line is drawn in the color {\it color}.
143
144 The coordinates may be numeric values or node-relative coordinates (see \gotomacro\addnode).
145 \emacroexp
146
147 \macroexp{\definelinecap {<name>}{<code>}{<width>}}
148 Defines a linecap by the name of {\it name}.
149 {\it code} is the code which draws the linecap (see \gotoanchor{internal-pdfdraw}{Internals of pdfDraw}), and {\it width} is the width of the linecap.
150
151 The provided linecaps are:
152
153 \def\drawlinecap#1{$\vcenter{\hbox to\csname linecap@#1@wd\endcsname pt{\pdfliteral{q \_pdfdraw_nattrans, 1 j 1 J \_pdfdraw_strokewidth\_space w \csname linecap@#1\endcsname\_space Q}\hfil}}$}
154 \centerline{\vbox{\tabskip=.5cm\halign{&\hfil\gdef\@@{#}{\tt\@@}: \tabskip=\z@&\_gobble{#}\drawlinecap\@@\tabskip=.5cm\cr
155 >&&<&&|-&&-|&&>>&&<<&&o&\cr
156 }}}
157
158 There is also an empty linecap {\tt-}.
159 \emacroexp
160
161 Outside of drawing environments, \pdftoolbox{} provides a macro to make diagrams, \macro\drawdiagram.
162 Its usage is \getmacrousageB{\drawdiagram {<table>}{<arrows>}}.
163 {\it table} is a normal \TeX{} alignment table (similar format as \macro\halign{}, without the preamble).
164 {\it arrows} is a collection of \gotomacro\diagarrow{} macro calls.
165
166 \macroexp{\diagarrow {<options>}}
167 Draws an arrow in a \macro\drawdiagram{} diagram.
168 {\it options} contains the following keys:
169 \blist
170 \item {\tt from} (required): the cell from which to start the arrow.
171 Cells start indexing at \inlinecode|{1,1}| for the top left cell where the first number is the row and the second the column;
172 \item {\tt to} (required): the cell to end the arrow;
173 \item {\tt left cap} (default {\tt-}): the start linecap;
174 \item {\tt right cap} (default {\tt>}): the end linecap;
175 \item {\tt color} (default {\tt black}): the color to draw the arrow in;
176 \item {\tt x off} (default {\tt0pt}): the $x$-axis offset;
177 \item {\tt y off} (default {\tt0pt}): the $y$-axis offset;
178 \item {\tt text}: the text to add on the arrow;
179 \item {\tt x distance} (default {\tt0pt}): the amount to move the text on the $x$-axis;
180 \item {\tt y distance} (default {\tt0pt}): the amount to move the text on the $y$-axis;
181 \item {\tt slide} (default {\tt.5}): where to place the text relative to the arrow;
182 \item {\tt curve}: the amount to curve the arrow;
183 \item {\tt dashed} (valueless): add to make the arrow line dashed;
184 \item {\tt dotted} (valueless): add to make the arrow line dotted;
185 \item {\tt origin orient}: the placement of the start of the arrow relative to the origin\hfill\break (a pair like \inlinecode|{left,bottom}|);
186 \item {\tt dest orient}: the placement of the end of the arrow relative to the destination\hfill\break (a pair like \inlinecode|{left,bottom}|).
187 \elist
188 \emacroexp
189
190 So for example,
191
192 \bgroup\parindent=\z@
193 \blisting
194 \drawdiagram{
195 A&B\cr
196 C&D
197 }{
198 \diagarrow{from={1,1}, to={1,2}, left cap=<<}
199 \diagarrow{from={1,2}, to={2,2}, color=rgb{1 0 0}, text={hello}, x distance=.5cm}
200 \diagarrow{from={2,2}, to={2,1}, curve=10pt, origin orient={xcenter,bottom}, dest orient={xcenter,bottom}}
201 \diagarrow{from={2,1}, to={1,1}, dashed, left cap=o, right cap=o}
202 }
203 \elisting
204 \egroup
205
206 Will yield
207
208 \centerline{\drawdiagram{
209 A&B\cr
210 C&D
211 }{
212 \diagarrow{from={1,1}, to={1,2}, left cap=<<}
213 \diagarrow{from={1,2}, to={2,2}, color=rgb{1 0 0}, text={hello}, x distance=.5cm}
214 \diagarrow{from={2,2}, to={2,1}, curve=10pt, origin orient={xcenter,bottom}, dest orient={xcenter,bottom}}
215 \diagarrow{from={2,1}, to={1,1}, dashed, left cap=o, right cap=o}
216 }}
217
218 Between each row of the diagram, space of width \macro\diagrowbuf{} is added.
219 Between each column, \macro\diagcolbuf.
220 The height of each row is at least \macro\diagrowheight{} and the width of each column is at least \macro\diagcolwidth.
221
222 \subsection{Listings}
223
224 In {\tt pdfGraphics/ptb-listings.tex}, \pdftoolbox{} provides macros for writing code listings.
225 The mechanism for how \pdftoolbox's listing works is greatly inspired by Petr Ol\v s\'ak's \url{https://ctan.org/pkg/optex?lang=en}{Op\TeX}.
226 The mechanism is largely the same, though the implementation may differ.
227
228 \macroexp{\setupverb}
229 This will set up a verbatim environment, essentially changing all special category codes to $12$.
230 \emacroexp
231
232 \macroexp{\blisting <first line> ... \elisting}
233 Writes {\tt...} in a verbatim environment, with syntax highlighting if set (see \gotomacro\loadsyntax{} and \gotomacro\setsyntax).
234 {\it first line} (the rest of the line after \macro\blisting) will be executed as normal (so you can set syntax here; see \gotomacro\setsyntax).
235 The line number of each line in the listing is stored in \macro\lstlinenum\anchormacro\lstlinennum, which is not reset after each listing.
236 \emacroexp
237
238 \macroexp{\listfile {<file>}[<start>-<end>]}
239 Creates a listing from file {\it file}.
240 Reads between lines {\it start} and {\it end} (inclusive).
241 If {\it start} isn't provided, starts from $1$.
242 If {\it end} isn't provided reads until the end (actually a large number).
243 \emacroexp
244
245 \macroexp{\loadsyntax {<language>}}
246 Loads in the necessary information for {\it language} syntax highlighting.
247 The information is input from the ptb-syntax file {\tt ptb-syntax-{\it language}}.
248 See the \gotoanchor{internal-listings}{internals of this section} for more information on how to write such a file.
249
250 Currently \pdftoolbox{} provides support for syntax highlighting of \TeX{} ({\it language} is {\tt TeX}) and of C ({\it language} is {\tt C}).
251 \emacroexp
252
253 \macroexp{\setsyntax {<language>}}
254 Sets the syntax to be used for syntax highlighting.
255 This must be used after \macro\loadsyntax{} for {\it language}.
256 \emacroexp
257
258 Some useful macros for customizing syntax highlighting are the following:
259 \blist
260 \item \macro\lstlineskip: the space added between each line in the listing;
261 \item \macro\lstvbuf: the space added before and after the listing;
262 \item \macro\lstlinenumbuf: the kerning added between the number and code on each line in the listing;
263 \item \macro\lstnumfontset: sets the font (and whatever else, e.g. color) of the numbers of each line in the listing;
264 \item \macro\lstfontset: sets the font (and whatever else, e.g. color) of the content of each line;
265 \item \macro\lststrut: the strut added to each line in the listing (for uniform spacing).
266 \elist
267
268 Some useful colors to be aware of:
269 \blist
270 \item {\tt lst-fg}: the default foreground color of the listing;
271 \item {\tt lst-bg}: the background color of the listing;
272 \item {\tt lst-comment}: the colors of comments (must be activated in the ptb-syntax file);
273 \item {\tt lst-number}: the colors of numbers (must be activated in the ptb-syntax file).
274 \elist
275
276 \pdftoolbox{} also provides a token list \macro\everylisting{} which is inserted before every listing.
277 So for example doing \inlinecode|\everylisting={\lstlinenum=0}| will reset the line numbering before each listing.
278