summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/pstricks/psd-help.tex
blob: 0c4bf708ab0b156a42982c3d0848ba10d87a82d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
%% BEGIN psd-help.tex

\appendix\part*{Help}

\Section{Boxes\label{S-boxes}}

Many of the PSTricks macros have an argument for text that is processed in
restricted horizontal mode (in \LaTeX{} parlance, LR-mode) and then transformed
in some way. This is always the macro's last argument, and it is written
"{<stuff>}" in this \emph{User's Guide}. Examples are the framing, rotating,
scaling, positioning and node macros. I will call these ``LR-box'' macros, and
use framing as the leading example in the discussion below.

In restricted horizontal mode, the input, consisting of regular characters and
boxes, is made into one (long or short) line. There is no line-breaking, nor
can there be vertical mode material such as an entire displayed equation.
However, the fact that you can include another box means that this isn't
really a restriction.

For one thing, alignment environments such as "\halign" or \LaTeX's "tabular"
are just boxes, and thus present no problem. Picture environments and the box
macros themselves are also just boxes. Actually, there isn't a single PSTricks
command that cannot be put directly in the argument of an LR-box macro.
However, entire paragraphs or other vertical mode material such as displayed
equations need to be nested in a "\vbox" or \LaTeX{} "\parbox" or "minipage".
\LaTeX{} users should see "fancybox.sty" and its documentation, "fancybox.doc",
for extensive tips and trick for using LR-box commands.

The PSTricks LR-box macros have some features that are not found in most other
LR-box macros, such as the standard \LaTeX{} LR-box commands.

With \LaTeX{} LR-box commands, the contents is always processed in text mode,
even when the box occurs in math mode. PSTricks, on the other hand, preserves
math mode, and attempts to preserve the math style as well. \TeX{} has four
math styles: text, display, script and scriptscript. Generally, if the box
macro occurs in displayed math (but not in sub- or superscript math), the
contents are processed in display style, and otherwise the contents are
processed in text style (even here the PSTricks macros can make mistakes, but
through no fault of their own). If you don't get the right style, explicitly
include a "\textstyle", "\displaystyle", "\scriptstyle" or
"\scriptscriptstyle" command at the beginning of the box macro's argument.

  In case you want your PSTricks LR-box commands to treat math in the same as
your other LR-box commands, you can switch this feature on and off with the
commands
\begin{Ex}
  \object  \psmathboxtrue
  \object  \psmathboxfalse
\end{Ex}

You can  have commands (such as, but not restricted to, the math style
commands) automatically inserted at the beginning of each LR-box using the
  \Mac  \everypsbox{commands}
command.\footnote{This is a token register.}

If you would like to define an LR-box environment <name> from an LR-box
command <cmd>, use
  \Mac  \pslongbox{name}{cmd}
For example, after
\begin{LVerbatim}
  \pslongbox{MyFrame}{\psframebox}
\end{LVerbatim}
you can write
\begin{LVerbatim}
  \MyFrame <stuff>\endMyFrame
\end{LVerbatim}
instead of
\begin{LVerbatim}
  \psframebox{<stuff>}
\end{LVerbatim}
Also, \LaTeX{} users can write
\begin{LVerbatim}
  \begin{MyFrame} <stuff>\end{MyFrame}
\end{LVerbatim}
It is up to you to be sure that <cmd> is a PSTricks LR-box command; if it
isn't, nasty errors can arise.

Environments like have nice properties:
\begin{itemize}
  \item The syntax is clearer when <stuff> is long.
  \item It is easier to build composite LR-box commands. For example, here is
a framed minipage environment for \LaTeX:
\begin{LVerb}
  \pslongbox{MyFrame}{\psframebox}
  \newenvironment{fminipage}%
    {\MyFrame\begin{minipage}}%
    {\end{minipage}\endMyFrame}
\end{LVerb}
  \item You include verbatim text and other "\catcode" tricks in <stuff>.
\end{itemize}

The rest of this section elaborates on the inclusion of verbatim text in
LR-box environments and commands, for those who are interested. "fancybox.sty"
also contains some nice verbatim macros and tricks, some of which are useful
for LR-box commands.

The reason that you cannot normally include verbatim text in an LR-box
commands argument is that \TeX{} reads the whole argument before processing the
"\catcode" changes, at which point it is too late to change the category
codes. If this is all Greek to you,\footnote{%
Incidentally, many foreign language macros, such as "greek.tex", use
"\catcode" tricks which can cause problems in LR-box macros.} then just try
this \LaTeX{} example to see the problem:
\begin{LVerbatim}
  \psframebox{\verb+\foo{bar}+}
\end{LVerbatim}

The LR-box environments defined with \n\pslongbox{} do not have this problem
because <stuff> is not processed as an argument. Thus, this works:
\begin{example}
  \pslongbox{MyFrame}{\psframebox}
  \MyFrame \verb+\foo{bar}+\endMyFrame
\end{example}

The commands
\begin{Ex}
  \object  \psverbboxtrue
  \object  \psverbboxfalse
\end{Ex}
switch into and out of, respectively, a special PSTricks mode that lets you
include verbatim text in any LR-box command. For example:
\begin{example}
  \psverbboxtrue
  \psframebox{\verb+\foo{bar}+}
\end{example}
However, this is not as robust. You must explicitly group color commands in
<stuff>, and LR-box commands that usually ignore spaces that follow
"{<stuff>}" might not do so when \n\psverbboxtrue{} is in effect.


\Section{Tips and More Tricks\label{tips}}

\faq{How do I rotate/frame this or that with \LaTeX?}

See "fancybox.sty" and its documentation.

\faq{How can I suppress the PostScript so that I can use my document with a
non-PostScript dvi driver?}

Put the command
  \Mac  \PSTricksOff
at the beginning of your document. You should then be able to print or preview
drafts of your document (minus the PostScript, and perhaps pretty strange
looking) with any dvi driver.


\faq{How can I improve the rendering of halftones?}

This can be an important consideration when you have a halftone in the
background and text on top. You can try putting
\begin{LVerb}
  \pstverb{106 45 {dup mul exch dup mul add 1.0 exch sub} setscreen}
\end{LVerb}
before the halftone, or in a header (as in headers and footers, not as in
PostScript header files),  if you want it to have an effect on every page.

"setscreen" is a device-dependent operator.

\faq{What special characters can be active with PSTricks?}

\Section{Including PostScript code\label{S-raw}}

To learn about the PostScript language, consult Adobe's \emph{PostScript
Language Tutorial and Cookbook} (the ``Blue Book''), or Henry McGilton and
Mary Campione's \emph{PostScript by Example} (1992). Both are published by
Addison-Wesley. You may find that the Appendix of the Blue Book, plus an
understanding of how the stack works, is all you need to write simple code for
computing numbers (e.g., to specify coordinates or plots using PostScript).

You may want to define \TeX{} macros for including PostScript fragments in
various places. All \TeX{} macros are expanded before being passed on to
PostScript. It is not always clear what this means. For example, suppose you
write
\begin{LVerb}
  \SpecialCoor
  \def\mydata{23 43}
  \psline(!47 \mydata add)
  \psline(!47 \mydata\ add)
  \psline(!47 \mydata~add)
  \psline(!47 \mydata{} add)
\end{LVerb}
You will get a PostScript error in each of the \n\psline{} commands. To see
what the argument is expanding to, try use \TeX's "\edef" and "\show". E.g.,
\begin{LVerb}
  \def\mydata{23 43}
  \edef\temp{47 \mydata add}
  \show\temp
  \edef\temp{47 \mydata\ add}
  \show\temp
  \edef\temp{47 \mydata~add}
  \show\temp
  \edef\temp{47 \mydata{} add}
  \show\temp
\end{LVerb}
\TeX{} expands the code, assigns its value to "\temp", and then displays the
value of "\temp" on your console. Hit <return> to procede. You fill find that
the four samples expand, respectively, to:
\begin{LVerb}
  47 23 43add
  47 23 43\ add
  47 23 43\penalty \@M \ add
  47 23 43{} add
\end{LVerb}
All you really wanted was a space between the "43" and "add". The command
"\space" will do the trick:
\begin{LVerb}
  \psline(!47 \mydata\space add)
\end{LVerb}

You can include balance braces "{"~"}"; these will be passed on verbatim to
PostScript. However, to include an unbalanced left or right brace, you have to
use, respectively,
\begin{Ex}
  \object  \pslbrace
  \object  \psrbrace
\end{Ex}
Don't bother trying "\}" or "\{".

Whenever you insert PostScript code in a PSTricks argument, the dictionary on
the top of the dictionary stack is "tx@Dict", which is PSTrick's main
dictionary. If you want to define you own variables, you have two options:
\begin{description}
  \item[Simplest] Always include a "@" in the variable names, because PSTricks
never uses "@" in its variables names. You are at a risk of overflowing the
"tx@Dict" dictionary, depending on your PostScript interpreter. You are also
more likely to collide with someone else's definitions, if there are multiple
authors contributing to the document.
  \item[Safest] Create a dictionary named "TDict" for your scratch
computations. Be sure to remove it from the dictionary stack at the end of any
code you insert in an argument. E.g.,
\begin{LVerb}
  TDict 10 dict def TDict begin <your code> end
\end{LVerb}
\end{description}

\section{Troubleshooting\label{troubleshooting}}
\setcounter{faq}{0}

\faq{Why does the document bomb in the printer when the first item in a
\LaTeX{} file is a float?}

When the first item in a \LaTeX{} file is a float, "\special"'s in the preamble
are discarded. In particular, the "\special" for including PSTricks's header
file is lost. The workaround is to but something before the float, or to
include the header file by a command-line option with your dvi-to-ps driver.

\faq{I converted a \texttt{.dvi} file to PostScript, and then mailed it to a
colleague. It prints fine for me but bombs on her printer.}

Here is the most likely (but not the only) cause of this problem. The
PostScript files you get when using PSTricks can contain long lines. This
should be acceptable to any proper PostScript interpreter, but the lines can
get chopped when mailing the file. There is no way to fix this in PSTricks,
but you can make a point of wrapping the lines of your PostScript files when
mailing them. E.g., on UNIX you can use "uuencode" and "uudecode", or you can
use the following AWK script to wrap the lines:
\begin{LVerb}
  #! /bin/sh
  # This script wraps all lines
  # Usage (if script is named wrap):
  #    wrap < infile > outfile
  awk '
  BEGIN {
    N = 78    # Max line length
  }
  {  if (length($0)<=N)
      print
    else {
      currlength = 0
      for (i = 1; i <=NF; i++) {
        if ((currlength = currlength + length($i) + 1) > N) {
          printf "\n"
          printf "%s", $i
          currlength = length($i)
          }
        else
          printf \ %s", $i
        }
      printf "\n"
    }
  } '
\end{LVerb}

\faq{The color commands cause extraneous vertical space to be inserted.}

For example, this can happen if you start a \LaTeX{} "\parbox" or a "p{}"
column with a color command. The solution usually is to precede the color
command with "\leavevmode".


\faq{The color commands interfere with other color macros I use.}

Try putting the command \Main\altcolormode{} at the beginning of your document.
This may or may not help. Be extra careful that the scope of color commands
does not extend across pages. This is generally a less robust color scheme.

\faq{How do I stop floats from being the same color as surrounding material?}

That's easy: Just put an explicit color command at the beginning of the float,
e.g., \n\black.

\faq{When I use some color command in box macros or with \texttt{\string\setbox},
the colors get all screwed up.}

\label{colorboxproblems}%
If "\mybox" is a box register, and you write
\begin{LVerb}
  \green Ho Hum.
  \setbox\mybox=\hbox{Foo bar \blue fee fum}
  Hi Ho. \red Diddley-dee
  \box\mybox hum dee do
\end{LVerb}
then when "\mybox" is inserted, the current color is red and so "Foo bar"
comes out red (rather than green, which was the color in effect when the box
was set). The command that returns from \n\blue{} to the current color "green",
when the box is set, is executed after the "\hbox" is closed, which means that
"Hi Ho" is green, but "hum dee do" is still blue.

This odd behavior is due to the fact that \TeX{} does not support color
internally, the way it supports font commands. The first thing to do is to
explicitly bracket any color commands inside the box. Second, be sure that the
current color is black when setting the box. Third, make other explicit color
changes where necessary if you still have problems. The color scheme invoked
by \n\altcolormode{} is slightly better behaved if you follow the first two
rules.

Note that various box macros use "\setbox" and so these anomalies can arise
unexpectedly.

\endinput

%% END psd-help.tex