summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/dlfltxb/dlfltxbcodetips.tex
blob: 78527b70039ba57c7c7cc99f718ed76e754b0d52 (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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
\RequirePackage{etex}
\documentclass[11pt,oneside,a4paper,oldfontcommands,danish,english,article]{memoir}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage[widespace]{fourier}

\setlxvchars[\normalfont]

\settypeblocksize{*}{1.3\lxvchars}{1.618}

\setlrmargins{*}{*}{0.7}
\setulmargins{*}{*}{1}
\setlength\marginparwidth{4cm}

\checkandfixthelayout


\hfuzz=30pt


\usepackage{color}
\usepackage[colorlinks,breaklinks]{hyperref}
\definecolor{linkcolour}{rgb}{0,0.2,0.6}
\definecolor{citecolour}{rgb}{0,0.6,0.2}
\definecolor{urlcolour} {rgb}{0.8,0,0.8}
  
\hypersetup{
  pdftitle={The dlfltxbcodetips package},
  pdfauthor={Copyright \textcopyright\ \number\year\ Lars Madsen},
  linkcolor=linkcolour,citecolor=citecolour,
  filecolor=urlcolour,urlcolor=urlcolour,
  plainpages=false,
}
  
\ifpdf\else\usepackage{breakurl}\fi
\usepackage{memhfixc}

\clubpenalty=300
\widowpenalty=300

\usepackage{microtype}

\usepackage{amsmath,amssymb}
\usepackage[amsmath,thmmarks]{ntheorem}
\usepackage[round]{natbib}

\usepackage{dlfltxbcodetips}
\usepackage[loadsampleconfig]{dlfltxbmarkup}
\renewcommand\felineMarginAdjustment{\RaggedLeft}



\usepackage{dlfltxbmisc}
\usepackage{graphicx}

\chapterstyle{article}

\setsecheadstyle{\normalfont\large\bfseries\raggedright}


\reversemarginpar
\reversesidepartrue

\definecolor{shadecolor}{gray}{0.8}
\theorembodyfont{\normalfont}
\theoremseparator{.}
\NewShadedTheorem{caveat}{Caveat}


% until dlfltxbsd is released we will have to use the following
% construction

\usepackage{fancyvrb}
\fvset{fontsize=\footnotesize}

\newcommand\verbfile{\jobname.vrb}
\newenvironment{sourcedisplay}{%
\par\vskip0.5\baselineskip\noindent
\VerbatimOut{\verbfile}}{%
\endVerbatimOut%
\noindent
\begin{minipage}{0.48\linewidth}
\VerbatimInput{\verbfile}
\end{minipage}
\hfill
\begingroup%
\begin{minipage}{0.48\linewidth}
\begin{framed}
\input{\verbfile}
\end{framed}
\end{minipage}
\endgroup\vskip0.5\baselineskip}


\newenvironment{Sourcedisplay}{%
\par\vskip0.5\baselineskip\noindent
\VerbatimOut{\verbfile}}{%
\endVerbatimOut%
\noindent
\begin{minipage}{\linewidth}
\VerbatimInput{\verbfile}
\end{minipage}
\par\bigskip\noindent
\begin{minipage}{\linewidth}
\begin{framed}
\input{\verbfile}
\end{framed}
\end{minipage}
\vskip0.5\baselineskip}


\pagestyle{plain}

\begin{document}

\title{Code tips from ``Introduktion til \LaTeX''\\{\normalsize Or just the
    \textsf{\jobname} package}}
\author{Lars Madsen\thanks{Web:
    \url{http://home.imf.au.dk/daleif}\qquad Email: \url{daleif@imf.au.dk}}}
\maketitle

\tableofcontents*

\setsecnumdepth{part}

\chapter{Introduction}
\label{cha:introduction}

In my \LaTeX\ book \citep{ltxb} we present some macros that might be
helpful to the readers.  Some of these extra macros might be useful to
others as well so these macros have been included in the
\markup[nomk,sty]{dlfltxbcodetips} package. The package is published on \textsc{ctan} and the
package is released under the normal lppl license.

The >>\texttt{dlfltxb}<< part of the name simply stands for >>daleif<<
and \LaTeX\ book. The \markup[nomk,sty]{dlfltxbcodetips} package is the first
package in the >>\texttt{dlfltxb}<<-bundle which, over time, will
contain most of the home made packages that I use to create my book
(though not the book source itself).

Some of the macros might be better of included in the
\markup[nomk,sty]{mathtools} package by Morten Høgholm, but he is quite busy
elsewhere at the moment. over time some of the macros might be
imcluded in 

\newpage
\noindent
\emph{Note:} The macro \verb+\dbx+ will often be used to simulate some
text or mathematical material. 

\setsecnumdepth{section}

\chapter{Extra symbols}
\label{cha:extra-symbols}

\section{\texorpdfstring{A big version of \cs{times}}{A big version of 
    \textbackslash times}}
\label{sec:big-version-cstimes}



A few extra symbols have been created. First of is \markup{bigtimes}
which is a large operator version of \markup[nomk]{times}, but without
having to load special fonts.
\begin{sourcedisplay}
$\bigtimes_{n=1}^k A_n$
\[ \bigtimes_{n=1}^k A_n \]
\end{sourcedisplay}

\section{Negated up- and downarrows}
\label{sec:negat-up-down}

The package creates \markup{nuparrow} and \markup{ndownarrow} by
rotating and reflecting \markup[nomk]{nrightarrow} and 
\markup[nomk]{nleftarrow}
respectively.
\begin{sourcedisplay}
$ A  \nuparrow B$ \qquad
$ B \ndownarrow C$
\end{sourcedisplay}
The macros require the use of the \markup[nomk,sty]{graphicx} package,
which is not auto loaded.

\chapter{Fun with theorems}
\label{cha:fun-with-theorems}

\section{Shaded theorems with the ntheorem package}
\label{sec:shaded-theorems-with}

Even though we have the \markup[nomk,sty]{shadedthm} package, we can
easily do better if we are already using the
\markup[nomk,sty]{ntheorem} package. Simply use
\begin{syntax}
  \markup{NewShadedTheorem}
\end{syntax}
It has exactly the same syntax as the ordinary
\markup[nomk]{newtheorem}. Requirements: the
\markup[nomk,sty]{framed}, \markup[nomk,sty]{ntheorem},
(\texttt{x})\markup[nomk,sty]{color} packages and the definition of
the >>\texttt{shadecolor}<< (required by the \markup[nomk,sty]{framed} package).
\begin{sourcedisplay}
\theoremheaderfont{\bfseries}
\theoremseparator{.}
\NewShadedTheorem{thm}{Theorem}[chapter]
\NewShadedTheorem{lemma}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\begin{thm}
  normal test.
\end{thm}
\begin{thm*}
  un-numbered.
\end{thm*}
\begin{lemma}
  a lemma.
\end{lemma}
\begin{prop}
  a theorem with no background.
\end{prop}
\end{sourcedisplay}
In contrast to \markup[nomk,sty]{ntheorem}, the $*$-ed version created
by \markup[nomk]{NewShadedTheorem} is a version that does not print a
number.

\section{Theorems that start with a list}
\label{sec:theorems-that-start}

A theorem that starts with a list looks odd because the first item
comes directly after the heading.\footnote{Depends on the
  configuration.}
\makeatletter
\let\thm\thm@inner
\let\endthm\endthm@inner
\makeatother
\begin{sourcedisplay}
\begin{thm}
  \begin{enumerate}
  \item \dbx[2cm]
  \item \dbx[2cm]
  \item \dbx[2cm]
  \end{enumerate}
\end{thm}
\end{sourcedisplay}
The macro \markup{InsertTheoremBreak} helps.
\begin{sourcedisplay}
\begin{thm}
  \InsertTheoremBreak
  \begin{enumerate}
  \item \dbx[2cm]
  \item \dbx[2cm]
  \item \dbx[2cm]
  \end{enumerate}
\end{thm}
\begin{thm}
  \InsertTheoremBreak*
  \begin{enumerate}
  \item \dbx[2cm]
  \item \dbx[2cm]
  \item \dbx[2cm]
  \end{enumerate}
\end{thm}
\end{sourcedisplay}
\noindent The un-stared version remove the space above the list, the
stared version does not.

\begin{caveat*}
  If the theorem comes too close to a page break it is quite likely
  that the page break will end up between the theorem header and the
  start of the list.
\end{caveat*}

\chapter{Various features regarding alignment}
\label{cha:vari-feat-regard}

\section{Arrow between lines}
\label{sec:arrow-between-lines}

Sometimes lines in an alignment are related in the sense of \emph{from
which it follows}, usually indicated by $\Rightarrow$. We would like
to place this between the lines in a nice way. The following macro is
due to Morten Høgholm.
\begin{syntax}
  \markup{ArrowBetweenLines}\oarg{arrow}
  \markup{ArrowBetweenLines*}\oarg{arrow}
\end{syntax}
Simply hold back one column of alignment for the arrow:
\begin{sourcedisplay}
\begin{alignat}{2}
  && f(x) & = \dbx[2cm] \\
  \ArrowBetweenLines
  && g(x) & = - \dbx[2cm] \\
  \ArrowBetweenLines[\Downarrow]
  && h(x) & = 0
\end{alignat}
\end{sourcedisplay}
Note the height of the arrow line and that the line automatically does
not contain equation numbers. The stared version can be used to place
the arrows on the right. Though several alignment columns on each line
might become a problem.
\begin{sourcedisplay}
\begin{alignat}{2}
  f(x) & = \dbx[2cm] \\
  \ArrowBetweenLines*
   g(x) & = - \dbx[2cm] \\
  \ArrowBetweenLines*[\Downarrow]
   h(x) & = 0
\end{alignat}
\end{sourcedisplay}


\section{Switch dead space}
\label{sec:switch-dead-space}

The standard \markup[nomk,env]{equation} environment has the feature
that if the text before it is short and the formula likewise, then the
drop between the preceding text and the formula will be
\markup[length,nomk]{abovedisplayshortskip} instead of the usual
\markup[length,nomk]{abovedisplayskip}. The macros from the
\markup[nomk,sty]{amsmath} package does not have this feature (except
\markup[nomk,env]{equation*}).
\begin{sourcedisplay}
text
\[ a=b \]
text
\begin{align*}
  a=b
\end{align*}
\end{sourcedisplay}
The macro \markup{SwapDeadSpace} can simulate this feature
\begin{sourcedisplay}
text
\[ a=b \]
text
\begin{align*}
  \SwapDeadSpace
  a=b
\end{align*}
\end{sourcedisplay}

\section{Left alignment}
\label{sec:left-alignment}

In \cite{swanson}, Ellen Swanson presents some recommendations
regarding how to arrange displayed formulas. One thing she recommends
is alignment to the left and with all subsequent lines indented by
2\,em. 
\begin{align*}
\malign[-2pt]{2} 
  &\dbx[5cm]=\dbx[4cm]\\
  &\qquad{}=\dbx[6cm]\\
  &\qquad{}=\dbx[5cm]\,.
\end{align*}
or
\begin{align*}
\malign[-2pt]{2}
  &\dbx[8cm]\\
  &\qquad{}=\dbx[4cm]\\
  &\qquad{}=\dbx[6cm]\,.
\end{align*}
or
\begin{align*}
\malign[-2pt]{2} 
  &\dbx[5cm]=\dbx[4cm]\\
  &\qquad{}+\dbx[6cm]\\
  &\qquad{}\times\dbx[5cm]\,.
\end{align*}
and
\begin{align*}
\malign[-2pt]{2}
  &\dbx[8cm]\\
  &\qquad{}-\dbx[4cm]\\
  &\qquad{}\otimes\dbx[6cm]\,.
\end{align*}
But having to do all those indentations by hand quickly becomes quite
dull. Instead, align everything to the left, and pull back the first
line. This is what the following macro does.
\begin{syntax}
  \markup{PullBack}\oarg{number}
\end{syntax}
The optional argument is a number (without unit, em will be used)
indicating the amount of indentation. 2\,em is the default. Now simply
use \markup[nomk]{PullBack} instead of the >>\texttt{\&}<< on the
first line.
\begin{sourcedisplay}
\begin{align*}
  \PullBack f(x) + g(x) + \dbx[4cm] \\
  & = \dbx[5cm] \\
  & = \dbx[5cm] 
\end{align*}
\end{sourcedisplay}
The optional argument is usually used whenever the alignment is moved
to the right of the equal signs.
\begin{sourcedisplay}
\begin{align*}
  \PullBack[3] f(x) + g(x) + \dbx[4cm] \\
   ={} & \dbx[5cm] \\
   & + \dbx[5cm] 
\end{align*}
\end{sourcedisplay}

\section{Alignment with material encased in delimiters on different lines}
\label{sec:alignm-with-mater}

Swanson also recommends that if one has material encased with
delimiters and the delimiters are on different lines, then if space
permits, the material should be indented such that the relationship is
evident. Usually we would use a \markup[nomk]{phantom} to do this,
such as in the next example.
\begin{sourcedisplay}
\begin{align*}
  \dbx[5mm]&= \dbx[5mm]\bigl[{} \dbx[3cm]\\
   &\phantom{=\dbx[5mm]\bigl[{}}
   \times \dbx[3cm]{}\\
   &\phantom{=\dbx[5mm]\bigl[{}}
   - \dbx[3cm]{}\bigr]\\
   &=\dbx[3cm]
\end{align*}
\end{sourcedisplay}
The problem with this is that it gets tedious and prone to human
error. How about instead maintaining a stack of material determining
the indentation together with tools to reset, add to and pop the
stack. For this you can use the following macros
\begin{syntax}
  \markup{MathIndent}
  \markup{SetMathIndent}\marg{math code}
  \markup{AddtoMathIndent}\marg{math code}
  \markup{PopMathIndent}
  \markup{PopMathIndent*}
\end{syntax}
\markup[nomk]{MathIndent} is used to set a space corresponding to the
current indentation saved on the stack. \markup[nomk]{SetMthIndent}
takes its argument and saves it on the stack, calculates the current
math indent length and ends by typesetting the given argument, i.e. no
need to copy anything. Similarly the \markup[nomk]{AddtoMathIndent}
adds it argument to the stack and adds the length of it to the saved
math indent. So instead of copying code, now we simply encase it with
either \markup[nomk]{SetMathIndent} (for the initialisation) or
\markup[nomk]{AddtoMathIndent}. \markup[nomk]{PopMathIndent} is
similar to \markup[nomk]{MathIndent}, in that it sets a blank space
corresponding to the contents of the stack after we have popped off
the top item. \markup[nomk]{PopMathIndent*} pops the stack but does
\emph{not} set any space.


Now, an illustrative example might be in order:
\begin{Sourcedisplay}
\begin{align*}
\dbx ={} & \SetMathIndent{\dbx[1cm] \Bigl[} \dbx[6cm]  \\
   & \MathIndent   + \dbx[7cm]  \\
   & \MathIndent 
   \AddtoMathIndent{{} + \dbx \Bigl\{}
   \AddtoMathIndent{\dbx[2cm] + \Bigl(} \dbx[4cm] \\
   & 
   \MathIndent + \dbx[4cm] \Bigr) \\
   & \PopMathIndent + \dbx[6cm] \Bigr\} \\
   & \PopMathIndent + \dbx[6cm] \Bigr]
\end{align*}
\end{Sourcedisplay}
Notice the dual use of \markup[nomk]{AddtoMathIndent} such that we can
return to the indentation set by the >>\texttt{\{}<<.

Of course, non-balanced \markup[nomk]{left}--\markup[nomk]{right}
constructions may not be used.

\bibliographystyle{plainnat}
\bibliography{package_doc}



\end{document}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% TeX-source-specials-mode: t
%%% TeX-PDF-mode: nil
%%% End: