Latex Programming Hints

Basics

Layout

Commands

  • \setlength{ length_cmd }{ length_spec }
  • \addtolength{ length_cmd }{ length_spec }
  • \settowidth{ length_cmd }{ text }
  • \settoheight{ length_cmd }{ text }
  • \settodepth{ length_cmd }{ text }

Dimensions

  • \parskip
  • \parindent
  • \baselineskip

Output

Debugging

TeX commands

  • \typeout{ text }
  • \showoutput
  • \tracingonline=1
  • \tracingpages=1
  • \tracingparagraphs=1
  • \showbox{ box_cmd }
  • \showlists
  • \pausing=1

Example program analysis

Latex file that creates door badge \documentclass[letterpaper,11pt,oneside]{article}

\usepackage[pdftex]{graphics,color}

\makeatletter

Command allows the character @ to be used in commands

\setlength\parskip{0\p@ \@plus \p@}

set parskip to length zero with zero stretchability in the positive direction. This forces paragraphs to begin on the next line after the \par statement and that distance will not change depending on page content.

  • \p@ is a shortcut to pt
  • \@plus is a shortcut to plus 0

\renewcommand{\baselinestretch}{}

undefine the amount of additional line spacing a paragraph can have to expand into the desired length

\newcommand{\settototalheight}[2]{% \settoheight{#1}{#2}% \settodepth{\@tempdima}{#2}% \addtolength{#1}{\@tempdima}}

create command to set a length #1 to the total height of a chunk of text. The total height is height plus to depth of the text.

  • \@tempdima - a temporary length Not guaranteed to be the same after calling another command

\newcommand{\typeoutstandardlayout}{% \typeout{} \typeout{******************************************************} \typeout{Page height and width: \the\paperheight\space by \the\paperwidth} \typeout{Text height and width: \the\textheight\space by \the\textwidth} \typeout{Oddside and evenside margins: \the\oddsidemargin\space and \the\evensidemargin} \typeout{Topmargin and footskip: \the\topmargin\space and \the\footskip} \typeout{Headheight and headsep: \the\headheight\space and \the\headsep} \typeout{Columnsep and columnseprule: \the\columnsep\space and \the\columnseprule} \typeout{Marginparsep and marginparwidth: \the\marginparsep\space and \the\marginparwidth} \typeout{******************************************************} \typeout{} }

\newcommand*{\trimmark}{% \begin{picture}(0,0) \unitlength 1cm \thinlines \put(-2,0){\line(1,0){4}} \put(0,-2){\line(0,1){4}} \end{picture}} \makeatother

\newlength\tmplen \newlength\stockwidth \newlength\stockheight \newlength\trimtop \newlength\trimbottom \newlength\trimmedwidth \newlength\trimmedheight \newlength\maxwidth \newlength\maxtitleheight \newlength\titleheight \newlength\deptwidth

Define lengths that the document will be using

\newsavebox{\deptname} \newsavebox{\titleinfo}

Define the save boxes that the document will need.

\setlength\parindent{0pt} \setlength{\tabcolsep}{0mm}

\setlength\headheight{0pt} \setlength\headsep{0pt} \setlength\topmargin{25pt} \setlength\voffset{-1in} \setlength\hoffset{-1in}

Set \voffset and \hoffset to -1in so that the origin of the document in at the upper left corner.

\setlength\oddsidemargin{0mm} \setlength\textheight{\paperheight} \setlength\textwidth{\paperwidth} \setlength\fboxsep{5mm}

\setlength\trimmedwidth{150mm} \setlength\trimmedheight{60mm} \setlength\stockwidth{153mm} \setlength\stockheight{70mm} \setlength\trimtop{7mm}

Set the page and writable dimensions of the badge. Set the height of the top margin within the box.

\setlength\trimbottom{\stockheight} \addtolength\trimbottom{-\trimtop} \addtolength\trimbottom{-\trimmedheight}

Set \trimbottom the to the amount of additional line spacing required to drop from the bottom of the printable area to the bottom of the stock.

\definecolor{vandyblue}{cmyk}{1,0.60,0,0.10}

Define the color vandyblue as per spec page

\pagestyle{empty}

Kill page headers and footers

\begin{document} \typeoutstandardlayout \huge

\sbox{\deptname}{\color{white}Department of Biostatistics} \settowidth\deptwidth{\usebox\deptname} \setlength\maxtitleheight{\trimmedheight} \settototalheight{\tmplen}{\usebox\deptname} \addtolength\maxtitleheight{-\tmplen}

\newcommand{\badge}[1]{% \sbox\titleinfo{\color{white}#1}% \settowidth\tmplen{\usebox\titleinfo}% \ifdim\trimmedwidth<\tmplen% \setlength\tmplen{\trimmedwidth}% \addtolength\tmplen{-1pt}% \sbox{\titleinfo}{\resizebox{\tmplen}{!}{\usebox\titleinfo}}% \fi% \settototalheight\titleheight{\usebox\titleinfo} \typeout{height: \the\titleheight} \typeout{max title height: \the\maxtitleheight}

\ifdim\titleheight>\maxtitleheight \sbox{\titleinfo}{\resizebox*{!}{\maxtitleheight}{\usebox\titleinfo}} \fi \settowidth\tmplen{\usebox\titleinfo} \typeout{title width: \the\tmplen} \ifdim\deptwidth<\tmplen \setlength\maxwidth{\tmplen} \else \setlength\maxwidth{\deptwidth} \fi \typeout{new height: \the\titleheight} \typeout{new width: \the\maxwidth} \fcolorbox{vandyblue}{vandyblue}{\parbox{\stockwidth}{% \trimmark\hfill\trimmark\vspace*{\trimtop}\\[-\lineskip]% \hspace*{\fill}\parbox[t][\trimmedheight][c]{\maxwidth}{\usebox\titleinfo\\\usebox\deptname}\hspace*{\fill}\vspace*{trimbottom}\\[-\baselineskip]% \trimmark\hfill\trimmark}}}

\begin{center} \badge{\begin{tabular}{l} \textbf{\Huge Cole Beck}\Computer Systems Analyist II \end{tabular}}\\[-\baselineskip] \vspace{20mm} \badge{\begin{tabular}{l} \textbf{\Huge Dale Plummer}\Manager, Information Systems \end{tabular}}\\[-\baselineskip] \vspace{20mm} \badge{\begin{tabular}{l@{~~}r} \textbf{\Huge Charles Dupont}&Computer Systems Analyist I\\textbf{\Huge Jeremy Stephens}&Computer Systems Analyist I \end{tabular}}\\[-\baselineskip] \end{center} \end{document}
Topic revision: r2 - 04 Jun 2008, CharlesDupont
 

This site is powered by FoswikiCopyright © 2013-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback