source: doc/LaTeXmacros/common.sty@ b22b28e

Last change on this file since b22b28e was b22b28e, checked in by Peter A. Buhr <pabuhr@…>, 5 months ago

new checking for empty optional parameters in latex macros

  • Property mode set to 100644
File size: 16.0 KB
RevLine 
[b721578]1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%%
3%% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
4%%
5%% The contents of this file are covered under the licence agreement in the
6%% file "LICENCE" distributed with Cforall.
7%%
8%% common.tex --
9%%
10%% Author : Peter A. Buhr
11%% Created On : Sat Apr 9 10:06:17 2016
12%% Last Modified By : Peter A. Buhr
[b22b28e]13%% Last Modified On : Mon May 5 21:37:13 2025
14%% Update Count : 666
[b721578]15%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
[b22b28e]17% This latex idiom for checking empty optional parameters
18% \ifx#1\@empty\else\if\relax\detokenize{#1}\relax
19% first checks if there is no optional parameter specified: \name{...} versus \name[]{...}
20% second checks if the optional parameter is specified but empty: \name[]{...} versus \name[...]{...}
21
[b721578]22\setlength{\textheight}{9in}
23%\oddsidemargin 0.0in
24\renewcommand{\topfraction}{0.8} % float must be greater than X of the page before it is forced onto its own page
25\renewcommand{\bottomfraction}{0.8} % float must be greater than X of the page before it is forced onto its own page
26\renewcommand{\floatpagefraction}{0.8} % float must be greater than X of the page before it is forced onto its own page
27\renewcommand{\textfraction}{0.0} % the entire page maybe devoted to floats with no text on the page at all
28
[8f7109c]29\lefthyphenmin=3 % hyphen only after 4 characters
30\righthyphenmin=3
[b721578]31
32\usepackage[ignoredisplayed]{enumitem} % do not affect trivlist
33\setlist{labelsep=1ex}% global
[63a7394]34\setlist{topsep=0pt}% global
35\setlist[itemize]{parsep=0.25ex,itemsep=0.25ex,listparindent=\parindent}% global
[b721578]36\setlist[itemize,1]{label=\textbullet}% local
37%\renewcommand{\labelitemi}{{\raisebox{0.25ex}{\footnotesize$\bullet$}}}
[63a7394]38\setlist[enumerate]{parsep=0.25ex,itemsep=0.25ex,listparindent=\parindent}% global
[75a0eae]39\setlist[enumerate,2]{labelsep=*,align=parleft}% local
[63a7394]40\setlist[description]{itemsep=0pt,listparindent=\parindent,leftmargin=\parindent,labelsep=1.5ex}
[b721578]41
42% Names used in the document.
43
44\usepackage{xspace}
[cc022a9]45\newcommand{\CFAIcon}{\textsf{C\raisebox{\depth}{\rotatebox{180}A}}} % Cforall icon
[b721578]46\newcommand{\CFA}{\protect\CFAIcon\xspace} % CFA symbolic name
47\newcommand{\CFL}{\textrm{Cforall}\xspace} % Cforall non-icon name
[1bb76ad]48\newcommand{\Celeven}{\textrm{C1\hspace*{-0.4ex}1}\xspace} % C11 symbolic name
[022bce0]49
[b721578]50\newcommand{\CCIcon}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}} % C++ icon
51% numbers disallowed in latex variables names => use number names
[1bb76ad]52\newcommand{\CCeleven}{\protect\CCIcon{1\hspace*{-0.4ex}1}\xspace} % C++11 symbolic name
[b721578]53\newcommand{\CCfourteen}{\protect\CCIcon{14}\xspace} % C++14 symbolic name
54\newcommand{\CCseventeen}{\protect\CCIcon{17}\xspace} % C++17 symbolic name
55\newcommand{\CCtwenty}{\protect\CCIcon{20}\xspace} % C++20 symbolic name
[022bce0]56\newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace} % C++ symbolic name
57\newcommand{\Cpp}[1][]{\CC{#1}} % C++ synonym
58
[966b4c6]59\newcommand{\Csharp}{C\raisebox{-0.7ex}{\relsize{2}$^\sharp$}\xspace} % C# symbolic name
[b721578]60
61%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62
[966b4c6]63\usepackage[scaled=0.85]{helvet} % descent Helvetica font and scale to times size
64\usepackage[T1]{fontenc}
[7a15b7e]65\usepackage{relsize} % must be after change to small or selects old size
66\usepackage{rotating}
67\usepackage{calc} % latex arithmetic
68
[b721578]69% remove special-character warning in PDF side-bar names
70\@ifpackageloaded{hyperref}{
71 \pdfstringdefDisableCommands{
72 \def\CFA{\CFL}
73 \def\Celeven{C11\xspace}
74 \def\CC{C++\xspace}
75 \def\CCeleven{C++11\xspace}
76 \def\CCfourteen{C++14\xspace}
77 \def\CCseventeen{C++17\xspace}
78 \def\CCtwenty{C++20\xspace}
79 \def\Csharp{C\#\xspace}
80 \def\lstinline{\xspace}% must use {} as delimiters, e.g., \lstinline{...}
81 }{}
82}
83
84% parindent is relative, i.e., toggled on/off in environments like itemize, so store the value for
85% use rather than use \parident directly.
86\newlength{\parindentlnth}
87\setlength{\parindentlnth}{\parindent}
88
89% reduce size of chapter/section titles
90\def\@makechapterhead#1{%
91 \vspace*{50\p@}%
92 {\parindent \z@ \raggedright \normalfont
93 \ifnum \c@secnumdepth >\m@ne
94 \large\bfseries \@chapapp\space \thechapter
95 \par\nobreak
96 \vskip 5\p@
97 \fi
98 \interlinepenalty\@M
99 \Large \bfseries #1\par\nobreak
100 \vskip 50\p@
101 }}
102\def\@makeschapterhead#1{%
103 \vspace*{50\p@}%
104 {\parindent \z@ \raggedright
105 \normalfont
106 \interlinepenalty\@M
107 \Large \bfseries #1\par\nobreak
108 \vskip 50\p@
109 }}
110\renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.5ex \@plus .2ex}{\normalfont\large\bfseries}}
111\renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.75ex \@plus -1ex \@minus -.2ex}{1.25ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
112\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}}
113\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}}
114\renewcommand\subparagraph{\@startsection{subparagraph}{4}{\z@}{-1.5ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries\itshape}}
115
116\newcommand{\italic}[1]{\emph{\hyperpage{#1}}}
117\newcommand{\Definition}[1]{\textbf{\hyperpage{#1}}}
[e693572]118\newcommand{\see}{\protect\@ifstar\@ssee\@see}
119\newcommand{\@ssee}[1]{(See #1)}
120\newcommand{\@see}[1]{(see #1)}
121
122% index macros
[b721578]123
124% Define some commands that produce formatted index entries suitable for cross-references.
125% ``\spec'' produces entries for specifications of entities. ``\impl'' produces entries for their
126% implementations, and ``\use'' for their uses.
127
128% \newcommand{\bold}[1]{{\bf #1}}
129% \def\spec{\@bsphack\begingroup
130% \def\protect##1{\string##1\space}\@sanitize
131% \@wrxref{|bold}}
132\def\impl{\@bsphack\begingroup
133 \def\protect##1{\string##1\space}\@sanitize
134 \@wrxref{|Definition}}
135\newcommand{\indexcode}[1]{{\lstinline$#1$}}
136\def\use{\@bsphack\begingroup
137 \def\protect##1{\string##1\space}\@sanitize
138 \@wrxref{|hyperpage}}
139\def\@wrxref#1#2{\let\thepage\relax
140 \xdef\@gtempa{\write\@indexfile{\string
141 \indexentry{#2@{\lstinline$#2$}#1}{\thepage}}}\endgroup\@gtempa
142 \if@nobreak \ifvmode\nobreak\fi\fi\@esphack}
143%\newcommand{\use}[1]{\index{#1@{\lstinline$#1$}}}
144%\newcommand{\impl}[1]{\index{\protect#1@{\lstinline$\protect#1$}|Definition}}
145
146% inline text and lowercase index: \Index{inline and lowercase index text}
147\newcommand{\Index}{\@ifstar\@sIndex\@Index}
148% inline text and as-in index: \Index[as-is index text]{inline text}
[b22b28e]149\newcommand{\@Index}[2][\@empty]{\lowercase{\def\temp{#2}}#2\ifx#1\@empty\else\if\relax\detokenize{#1}\relax\index{\temp}\else\index{#1@{\protect#2}}\fi\fi}
[b721578]150% inline text but index with different as-is text: \Index[index text]{inline text}
[b22b28e]151\newcommand{\@sIndex}[2][\@empty]{#2\ifx#1\@empty\else\if\relax\detokenize{#1}\relax\index{#2}\else\index{#1@{\protect#2}}\fi\fi}
[b721578]152
153% inline text and code index (cannot use ©)
154\newcommand{\Indexc}[2][\@empty]{\lstinline[#1]$#2$\index{#2@\lstinline[#1]$#2$}}
155% code index (cannot use ©)
156\newcommand{\indexc}[2][\@empty]{\index{#2@\lstinline[#1]$#2$}}
157
158% Denote newterms in particular font and index them without particular font and in lowercase, e.g., \newterm{abc}.
159% The option parameter provides an index term different from the new term, e.g., \newterm[\texttt{abc}]{abc}
160% The star version does not lowercase the index information, e.g., \newterm*{IBM}.
161\newcommand{\newtermFontInline}{\emph}
162\newcommand{\newterm}{\protect\@ifstar\@snewterm\@newterm}
[b22b28e]163\newcommand{\@snewterm}[2][\@empty]{{\newtermFontInline{#2}}\ifx#1\@empty\else\if\relax\detokenize{#1}\relax\index{#2}\else\index{#1@{\protect#2}}\fi\fi}
164\newcommand{\@newterm}[2][\@empty]{\lowercase{\def\temp{#2}}{\newtermFontInline{#2}}\ifx#1\@empty\else\if\relax\detokenize{#1}\relax\index{\temp}\else\index{#1@{\protect#2}}\fi\fi}
[b721578]165
[7a15b7e]166% \snake{<identifier>}
167% Improves writing of snake case (or any convention that uses _) by allowing
168% line breaks after _. Disables commands inside the block and formats the
169% identifier to look like code.
170\newcommand*\snake[1]{\snakefont{\expandafter\snake@next\detokenize{#1}\@nil}}
171
172% \snakefont{<text>}
173% Command used by \snake, you may renew the command to change its formating.
174\newcommand*\snakefont[1]{\LstBasicStyle{#1}}
175
176% Thanks Manuel of TeX Stack exchange. (I got the base pattern from one of
177% their answers.) Note: \@nil should never be defined.
178\newcommand*\snake@next[1]{\ifx\@nil#1\else
179 \expandafter\ifx\string_#1\string_\allowbreak\else#1\fi
180 \expandafter\snake@next\fi
181}
182
183% \lang{<language>}{<code>}
184% Use the listings package to format the snipit of <code> in <language>.
185\newcommand{\lang}[2]{\lstinline[language=#1]{#2}}
186
[b721578]187% Latin abbreviation
188\newcommand{\abbrevFont}{\textit} % set empty for no italics
189% If not followed by a comma or colon, add a comma.
190\newcommand{\CheckCommaColon}{\@ifnextchar{,}{}{\@ifnextchar{:}{}{,\xspace}}}
191% If not followed by a period, add a period.
192\newcommand{\CheckPeriod}{\@ifnextchar{.}{}{.\xspace}}
193
194\newcommand{\EG}{\abbrevFont{e}.\abbrevFont{g}.}
[3b69398]195\newcommand{\eg}{\EG\protect\CheckCommaColon}
[cc022a9]196
[b721578]197\newcommand{\IE}{\abbrevFont{i}.\abbrevFont{e}.}
[3b69398]198\newcommand{\ie}{\IE\protect\CheckCommaColon}
[cc022a9]199
[b721578]200\newcommand{\ETC}{\abbrevFont{etc}}
[3b69398]201\newcommand{\etc}{\ETC\protect\CheckPeriod}
[cc022a9]202
[b721578]203\newcommand{\ETAL}{\abbrevFont{et}~\abbrevFont{al}}
[3b69398]204\newcommand{\etal}{\ETAL\protect\CheckPeriod}
[cc022a9]205
[b721578]206\newcommand{\VIZ}{\abbrevFont{viz}}
[3b69398]207\newcommand{\viz}{\VIZ\protect\CheckPeriod}
[b721578]208
[966b4c6]209\newcommand{\VS}{\abbrevFont{vs}}
[3b69398]210\newcommand{\vs}{\VS\protect\CheckPeriod}
[966b4c6]211
[b721578]212\newenvironment{cquote}{%
[e693572]213 \list{}{\topsep=\lst@aboveskip\parskip=0pt\partopsep=0pt\itemsep=0pt\parsep=0pt\listparindent=0pt\leftmargin=\parindentlnth\rightmargin=0pt}%
[b721578]214 \item\relax
[e693572]215 \lstset{resetmargins=true}
[b721578]216}{%
217 \endlist
218}% cquote
219
220\newenvironment{rationale}{%
221 \begin{cquote}\noindent$\Box$\enspace
222}{%
223 \hfill\enspace$\Box$\end{cquote}
224}%
225
226% blocks and titles
227\newcommand{\define}[1]{\emph{#1\/}\index{#1}}
228\newcommand{\rewriterules}{\paragraph{Rewrite Rules}~\par\noindent}
229\newcommand{\examples}{\paragraph{Examples}~\par\noindent}
230\newcommand{\semantics}{\paragraph{Semantics}~\par\noindent}
231\newcommand{\constraints}{\paragraph{Constraints}~\par\noindent}
232\newcommand{\predefined}{\paragraph{Predefined Identifiers}~\par\noindent}
233
234% BNF macros
235\newenvironment{syntax}{
236\paragraph{Syntax}
237\begin{cquote}
238\begin{description}[noitemsep,leftmargin=\parindentlnth]
239}{
240\end{description}
241\end{cquote}
242}
243% \def\syntax{\paragraph{Syntax}\trivlist\parindent=.5in\item[\hskip.5in]}
244%\let\endsyntax=\endtrivlist
245\newcommand{\lhs}[1]{\item[\emph{#1:}\index{#1@{\emph{#1}}|italic}]~\ignorespaces}
246\newcommand{\oldlhs}[1]{\item[\emph{#1:}\index{#1@{\emph{#1}}|italic}~\dots]~}
247\newcommand{\rhs}{\hfil\newline}
248\newcommand{\nonterm}[1]{\emph{#1}\index{#1@{\emph{#1}}|italic}}
249\newcommand{\opt}{$_{opt}$\ }
250
251\usepackage{varioref} % extended references
252% adjust varioref package with default "section" and "page" titles, and optional title with faraway page numbers
253% \VRef{label} => Section 2.7, \VPageref{label} => page 17
254% \VRef[Figure]{label} => Figure 3.4, \VPageref{label} => page 17
255\renewcommand{\reftextfaceafter}{\unskip}
256\renewcommand{\reftextfacebefore}{\unskip}
257\renewcommand{\reftextafter}{\unskip}
258\renewcommand{\reftextbefore}{\unskip}
259\renewcommand{\reftextfaraway}[1]{\unskip, p.~\pageref{#1}}
260\renewcommand{\reftextpagerange}[2]{\unskip, pp.~\pageref{#1}--\pageref{#2}}
[b22b28e]261\newcommand{\VRef}[2][Section]{\ifx#1\@empty\else\if\relax\detokenize{#1}\relax\else{#1}\nobreakspace\fi\fi\vref{#2}}
262\newcommand{\VRefrange}[3][Sections]{\ifx#1\@empty\else\if\relax\detokenize{#1}\relax\else{#1}\nobreakspace\fi\fi\vrefrange{#2}{#3}}
263\newcommand{\VPageref}[2][page]{\ifx#1\@empty\else\if\relax\detokenize{#1}\relax\else{#1}\nobreakspace\fi\fi\pageref{#2}}
264\newcommand{\VPagerefrange}[3][pages]{\ifx#1\@empty\else\if\relax\detokenize{#1}\relax\else{#1}\nobreakspace\fi\fi\pageref{#2}{#3}}
[b721578]265
266\let\Oldthebibliography\thebibliography
267\renewcommand\thebibliography[1]{
268 \Oldthebibliography{#1}
269 \setlength{\parskip}{0pt} % reduce vertical spacing between references
270 \setlength{\itemsep}{5pt plus 0.3ex}
271}%
272
273\usepackage{listings} % format program code
274\usepackage{lstlang}
275
[562ccf9]276\lst@AddToHook{OnEmptyLine}{\addtocounter{lstnumber}{-1}}% remove empty line number increment from listings
277
[b721578]278\newcommand{\LstBasicStyle}[1]{{\lst@basicstyle{#1}}}
279\newcommand{\LstKeywordStyle}[1]{{\lst@basicstyle{\lst@keywordstyle{#1}}}}
280\newcommand{\LstCommentStyle}[1]{{\lst@basicstyle{\lst@commentstyle{#1}}}}
281\newcommand{\LstStringStyle}[1]{{\lst@basicstyle{\lst@stringstyle{#1}}}}
[9586d22]282\newcommand{\LstNumberStyle}[1]{{\lst@basicstyle{\lst@numberstyle{#1}}}}
[b721578]283
284\newlength{\gcolumnposn} % temporary hack because lstlisting does not handle tabs correctly
285\newlength{\columnposn}
[01fb70a]286\setlength{\gcolumnposn}{3in}
[b721578]287\setlength{\columnposn}{\gcolumnposn}
[4e2a57ff]288\newcommand{\setgcolumn}[1]{\global\gcolumnposn=#1\global\columnposn=\gcolumnposn}
[b22b28e]289\newcommand{\C}[2][\@empty]{\ifx#1\@empty\else\if\relax\detokenize{#1}\relax\else\global\setlength{\columnposn}{#1}\global\columnposn=\columnposn\fi\fi\hfill\makebox[\textwidth-\columnposn][l]{\LstCommentStyle{#2}}}
290\newcommand{\CD}[2][\@empty]{\ifx#1\@empty\else\if\relax\detokenize{#1}\relax\else\global\setlength{\columnposn}{#1}\global\columnposn=\columnposn\fi\fi\hfill\makebox[\textwidth-\columnposn][l]{\LstBasicStyle{#2}}}
[b721578]291\newcommand{\CRT}{\global\columnposn=\gcolumnposn}
292
293% allow escape sequence in lstinline
294%\usepackage{etoolbox}
295%\patchcmd{\lsthk@TextStyle}{\let\lst@DefEsc\@empty}{}{}{\errmessage{failed to patch}}
296
297% allow adding to lst literate
298\def\addToLiterate#1{\protect\edef\lst@literate{\unexpanded\expandafter{\lst@literate}\unexpanded{#1}}}
299\lst@Key{add to literate}{}{\addToLiterate{#1}}
300
301\newcommand{\CFAStyle}{%
302\lstset{
303columns=fullflexible,
304basicstyle=\linespread{0.9}\sf, % reduce line spacing and use sanserif font
[9586d22]305stringstyle=\small\tt, % use typewriter font
[b721578]306tabsize=5, % N space tabbing
307xleftmargin=\parindentlnth, % indent code to paragraph indentation
308extendedchars=true, % allow ASCII characters in the range 128-255
[7a15b7e]309mathescape=false, % disable LaTeX math escape in CFA code $...$
[b721578]310keepspaces=true, %
311showstringspaces=false, % do not show spaces with cup
312showlines=true, % show blank lines at end of code
313aboveskip=4pt, % spacing above/below code block
314belowskip=2pt,
315numberstyle=\footnotesize\sf, % numbering style
316% replace/adjust listing characters that look bad in sanserif
[cc022a9]317literate=
[739495a]318% {-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.75ex}{0.1ex}}}}1
[022bce0]319 {-}{\raisebox{-1pt}{\ttfamily-}}1
[1bb76ad]320 {^}{\raisebox{0.6ex}{\(\scriptstyle\land\,\)}}1
321 {~}{\raisebox{0.3ex}{\(\scriptstyle\sim\,\)}}1
[75a0eae]322% {'}{\ttfamily'\hspace*{-0.4ex}}1
[7e8db9e]323% {`}{\ttfamily\upshape\hspace*{-0.3ex}`}1
324 {`}{\raisebox{-2pt}{\large\textasciigrave\hspace{-1pt}}}1
[cc022a9]325 {<-}{$\leftarrow$}2
326 {=>}{$\Rightarrow$}2
[739495a]327% {->}{\raisebox{-1pt}{\texttt{-}}\kern-0.1ex\textgreater}2,
[b721578]328}% lstset
329}% CFAStyle
330
331\ifdefined\CFALatin% extra Latin-1 escape characters
332\lstnewenvironment{cfa}[1][]{% necessary
333\lstset{
334language=CFA,
[9b96e90d]335escapechar=§, % LaTeX escape in CFA code §...§ (section symbol), emacs: C-q M-'
[b721578]336moredelim=**[is][\color{red}]{®}{®}, % red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
337%moredelim=**[is][\color{blue}]{ß}{ß}, % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
338%moredelim=**[is][\color{OliveGreen}]{¢}{¢}, % green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
339%moredelim=[is][\lstset{keywords={}}]{¶}{¶}, % keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^
340}% lstset
341\lstset{#1}% necessary
342}{}
343% inline code ©...© (copyright symbol) emacs: C-q M-)
344\lstMakeShortInline© % single-character for \lstinline
[9b96e90d]345
[b721578]346\else% regular ASCI characters
[9b96e90d]347
[b721578]348\lstnewenvironment{cfa}[1][]{% necessary
349\lstset{
350language=CFA,
351escapechar=\$, % LaTeX escape in CFA code
352moredelim=**[is][\color{red}]{@}{@}, % red highlighting @...@
353}% lstset
354\lstset{#1}% necessary
355}{}
356% inline code @...@ (at symbol)
357\lstMakeShortInline@ % single-character for \lstinline
358\fi%
359
[e693572]360\usepackage{tabularx} % if @ is used for lstMakeShortInline, allows @{}
361
[b721578]362% Local Variables: %
363% tab-width: 4 %
364% fill-column: 100 %
365% End: %
Note: See TracBrowser for help on using the repository browser.