This is an old revision of the document!
Tips and Tricks for LaTeX
- For the redefining the header, you can use
\markboth
– two parameters (left and right page) or\markright
with just one parameter\markboth{\uppercase{Summary}}{\uppercase{Summary}}
- You should note that a left-hand heading is generated by the last
\markboth
command before the end of the page, while a right-hand heading is generated by the first\markboth
or\markright
that comes on the page if there is one, otherwise by the last one before the page. (source)
\chaptermark
,\sectionmark
, … withfancyhdr
package- see http://en.wikibooks.org/wiki/LaTeX/Page_Layout for more details
- Useful page (and a figure) for lists:
- The if condition in TeX:
- construction if
\variable
is empty:The variable \if#\variable# is empty.\else contains \variable.\fi
(\variable
naturally cannot contain'#'
)The variable \ifx\@empty\variable is empty.\else contains \variable.\fi
- comparing two strings:
\newif\ifsame
\newcommand{\strcfstr}[2]{%
\samefalse
\begingroup
\def\1{#1}\def\2{#2}%
\ifx\1\2\endgroup \sametrue
\else \endgroup
\fi}- (The grouping is needed there to make '\1' and '\2' local but '\sametrue' global.)
- allocator
\newif
is used in a sequention:
a declaration\newif\ifsomething
setting either\somethingtrue
or\somethingfalse
and asking\ifsomething YES\else NO\fi
- foreach in TeX (thanks to TMA):
- If you want to
\dothis{}
with each word in\foreach{Peter, Paul, John, Ringo}
, you can do this as follows:\def\foreach#1{\first#1,,}
\def\first#1,{\if,#1,\else\dothis{#1}\expandafter\first\fi}
- and then write something here:
\def\dothis#1{ … whatever #1 … }
- Aligning an element in the line according to whether it fits in the rest of the line (TeX)
- always right-aligned (from Petr Olšák's TeXbook naruby):
\def\alignelemright #1\par{\unskip \nobreak\hfill\penalty71\hskip2em\hbox{}\nobreak\hfill \hbox{#1}\par}
- always left-aligned:
\def\alignelemleft #1\par{\unskip \hbox{} \hskip 0pt plus 1fil \penalty0 \hbox{#1}\hskip 0pt plus 1fill\hbox{}\par}
- align to the right, if it fits, or to the left in the new line:
\def\alignelemrightorleft #1\par{\unskip \nobreak\hfill\penalty71\hskip2em \hbox{#1}\par}
- Useful packages:
- Source printing:
fancyvrb
,listings
fancyhdr
- pseudocode
algorithmicx
počítání slov (a dalších věcí)
texcount soubor.tex
texcount -inc soubor.tex
… započítá správně slova i v souborech vložených v hlavním souboru pomocí \include
Podrobnosti v dokumentaci: texdoc texcount
Some PBML and SCTL-specific issues are here.