1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
2 | |
---|
3 | % Names used in the document. |
---|
4 | |
---|
5 | \newcommand{\CFA}{C$\mathbf\forall$\xspace} % set language symbolic name |
---|
6 | \newcommand{\CFL}{Cforall\xspace} % set language text name |
---|
7 | \newcommand{\CC}{C\kern-.1em\hbox{+\kern-.25em+}\xspace} % CC symbolic name |
---|
8 | \def\c11{ISO/IEC C} % C11 name (cannot have numbers in latex command name) |
---|
9 | |
---|
10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
11 | |
---|
12 | \makeatletter |
---|
13 | % allow escape sequence in lstinline |
---|
14 | %\usepackage{etoolbox} |
---|
15 | %\patchcmd{\lsthk@TextStyle}{\let\lst@DefEsc\@empty}{}{}{\errmessage{failed to patch}} |
---|
16 | |
---|
17 | % make fontsize "small" slightly larger, specifically for san serif (helvetica) in program code |
---|
18 | \renewcommand\small{% |
---|
19 | \@setfontsize\small{8.5}{11}% |
---|
20 | \abovedisplayskip 8.5pt \@plus 3pt \@minus 4pt |
---|
21 | \abovedisplayshortskip \z@ \@plus 2pt |
---|
22 | \belowdisplayshortskip 4pt \@plus 2pt \@minus 2pt |
---|
23 | \def\@listi{\leftmargin\leftmargini |
---|
24 | \topsep 4pt \@plus 2pt \@minus 2pt |
---|
25 | \parsep 2pt \@pluspt \@minuspt |
---|
26 | \itemsep \parsep}% |
---|
27 | \belowdisplayskip \abovedisplayskip |
---|
28 | } |
---|
29 | \usepackage{relsize} % must be after change to small or selects old size |
---|
30 | |
---|
31 | % reduce size of chapter/section titles |
---|
32 | \def\@makechapterhead#1{% |
---|
33 | \vspace*{50\p@}% |
---|
34 | {\parindent \z@ \raggedright \normalfont |
---|
35 | \ifnum \c@secnumdepth >\m@ne |
---|
36 | \large\bfseries \@chapapp\space \thechapter |
---|
37 | \par\nobreak |
---|
38 | \vskip 5\p@ |
---|
39 | \fi |
---|
40 | \interlinepenalty\@M |
---|
41 | \Large \bfseries #1\par\nobreak |
---|
42 | \vskip 50\p@ |
---|
43 | }} |
---|
44 | \def\@makeschapterhead#1{% |
---|
45 | \vspace*{50\p@}% |
---|
46 | {\parindent \z@ \raggedright |
---|
47 | \normalfont |
---|
48 | \interlinepenalty\@M |
---|
49 | \Large \bfseries #1\par\nobreak |
---|
50 | \vskip 50\p@ |
---|
51 | }} |
---|
52 | \renewcommand\section{\@startsection{section}{1}{\z@}{-3.0ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\large\bfseries}} |
---|
53 | \renewcommand\subsection{\@startsection{subsection}{2}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} |
---|
54 | \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}{-2.5ex \@plus -1ex \@minus -.2ex}{1.0ex \@plus .2ex}{\normalfont\normalsize\bfseries}} |
---|
55 | \renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}} |
---|
56 | |
---|
57 | % index macros |
---|
58 | \newcommand{\italic}[1]{\emph{\hyperpage{#1}}} |
---|
59 | \newcommand{\definition}[1]{\textbf{\hyperpage{#1}}} |
---|
60 | \newcommand{\see}[1]{\emph{see} #1} |
---|
61 | |
---|
62 | % reduce bullet size and spacing for "itemize" macro |
---|
63 | \renewcommand{\labelitemi}{{\raisebox{0.25ex}{\footnotesize$\bullet$}}} |
---|
64 | \renewenvironment{itemize}{\begin{list}{\labelitemi}{\topsep=5pt\itemsep=5pt\parsep=0pt}}{\end{list}} |
---|
65 | |
---|
66 | % Define some commands that produce formatted index entries suitable for cross-references. |
---|
67 | % ``\spec'' produces entries for specifications of entities. ``\impl'' produces entries for their |
---|
68 | % implementations, and ``\use'' for their uses. |
---|
69 | |
---|
70 | % \newcommand{\bold}[1]{{\bf #1}} |
---|
71 | % \def\spec{\@bsphack\begingroup |
---|
72 | % \def\protect##1{\string##1\space}\@sanitize |
---|
73 | % \@wrxref{|bold}} |
---|
74 | \def\impl{\@bsphack\begingroup |
---|
75 | \def\protect##1{\string##1\space}\@sanitize |
---|
76 | \@wrxref{|definition}} |
---|
77 | \newcommand{\indexcode}[1]{{\lstinline$#1$}} |
---|
78 | \def\use{\@bsphack\begingroup |
---|
79 | \def\protect##1{\string##1\space}\@sanitize |
---|
80 | \@wrxref{|hyperpage}} |
---|
81 | \def\@wrxref#1#2{\let\thepage\relax |
---|
82 | \xdef\@gtempa{\write\@indexfile{\string |
---|
83 | \indexentry{#2@{\lstinline$#2$}#1}{\thepage}}}\endgroup\@gtempa |
---|
84 | \if@nobreak \ifvmode\nobreak\fi\fi\@esphack} |
---|
85 | %\newcommand{\use}[1]{\index{#1@{\lstinline$#1$}}} |
---|
86 | %\newcommand{\impl}[1]{\index{\protect#1@{\lstinline$\protect#1$}|definition}} |
---|
87 | |
---|
88 | % inline text and lowercase index: \Index{inline and lowercase index text} |
---|
89 | % inline text and as-in index: \Index[as-is index text]{inline text} |
---|
90 | % inline text but index with different as-is text: \Index[index text]{inline text} |
---|
91 | \newcommand{\Index}{\@ifstar\@sIndex\@Index} |
---|
92 | \newcommand{\@Index}[2][\@empty]{\lowercase{\def\temp{#2}}#2\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi} |
---|
93 | \newcommand{\@sIndex}[2][\@empty]{#2\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi} |
---|
94 | |
---|
95 | \newcommand{\newtermFontInline}{\emph} |
---|
96 | \newcommand{\newterm}{\@ifstar\@snewterm\@newterm} |
---|
97 | \newcommand{\@newterm}[2][\@empty]{\lowercase{\def\temp{#2}}{\newtermFontInline{#2}}\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi} |
---|
98 | \newcommand{\@snewterm}[2][\@empty]{{\newtermFontInline{#2}}\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi} |
---|
99 | \makeatother |
---|
100 | |
---|
101 | \newenvironment{quote2}{% |
---|
102 | \list{}{\lstset{resetmargins=true}\leftmargin=\parindent\rightmargin\leftmargin}% |
---|
103 | \item\relax |
---|
104 | }{% |
---|
105 | \endlist |
---|
106 | }% quote2 |
---|
107 | \newenvironment{rationale}{% |
---|
108 | \begin{quotation}\noindent$\Box$\enspace |
---|
109 | }{% |
---|
110 | \hfill\enspace$\Box$\end{quotation} |
---|
111 | }% |
---|
112 | |
---|
113 | % blocks and titles |
---|
114 | \newcommand{\define}[1]{\emph{#1\/}\index{#1}} |
---|
115 | \newcommand{\rewrite}{\(\Rightarrow\)} |
---|
116 | \newcommand{\rewriterules}{\paragraph{Rewrite Rules}~\par\noindent} |
---|
117 | \newcommand{\examples}{\paragraph{Examples}~\par\noindent} |
---|
118 | \newcommand{\semantics}{\paragraph{Semantics}~\par\noindent} |
---|
119 | \newcommand{\constraints}{\paragraph{Constraints}~\par\noindent} |
---|
120 | \newcommand{\predefined}{\paragraph{Predefined Identifiers}~\par\noindent} |
---|
121 | |
---|
122 | % BNF macros |
---|
123 | \def\syntax{\paragraph{Syntax}\trivlist\parindent=.5in\item[\hskip.5in]} |
---|
124 | \let\endsyntax=\endtrivlist |
---|
125 | \newcommand{\lhs}[1]{\par{\emph{#1:}}\index{#1@{\emph{#1}}|italic}} |
---|
126 | \newcommand{\rhs}{\hfil\break\hbox{\hskip1in}} |
---|
127 | \newcommand{\oldlhs}[1]{\emph{#1: \ldots}\index{#1@{\emph{#1}}|italic}} |
---|
128 | \newcommand{\nonterm}[1]{\emph{#1\/}\index{#1@{\emph{#1}}|italic}} |
---|
129 | \newcommand{\opt}{$_{opt}$\ } |
---|
130 | |
---|
131 | % adjust varioref package with default "section" and "page" titles, and optional title with faraway page numbers |
---|
132 | % \VRef{label} => Section 2.7, \VPageref{label} => page 17 |
---|
133 | % \VRef[Figure]{label} => Figure 3.4, \VPageref{label} => page 17 |
---|
134 | \renewcommand{\reftextfaceafter}{\unskip} |
---|
135 | \renewcommand{\reftextfacebefore}{\unskip} |
---|
136 | \renewcommand{\reftextafter}{\unskip} |
---|
137 | \renewcommand{\reftextbefore}{\unskip} |
---|
138 | \renewcommand{\reftextfaraway}[1]{\unskip, p.~\pageref{#1}} |
---|
139 | \renewcommand{\reftextpagerange}[2]{\unskip, pp.~\pageref{#1}--\pageref{#2}} |
---|
140 | \newcommand{\VRef}[2][Section]{\ifx#1\@empty\else{#1}\nobreakspace\fi\vref{#2}} |
---|
141 | \newcommand{\VPageref}[2][page]{\ifx#1\@empty\else{#1}\nobreakspace\fi\pageref{#2}} |
---|
142 | |
---|
143 | % Go programming language |
---|
144 | \lstdefinelanguage{Golang}{ |
---|
145 | morekeywords=[1]{package,import,func,type,struct,return,defer,panic, recover,select,var,const,iota,},% |
---|
146 | morekeywords=[2]{string,uint,uint8,uint16,uint32,uint64,int,int8,int16, int32,int64, |
---|
147 | bool,float32,float64,complex64,complex128,byte,rune,uintptr, error,interface},% |
---|
148 | morekeywords=[3]{map,slice,make,new,nil,len,cap,copy,close,true,false, delete,append,real,imag,complex,chan,},% |
---|
149 | morekeywords=[4]{for,break,continue,range,goto,switch,case,fallthrough,if, else,default,},% |
---|
150 | morekeywords=[5]{Println,Printf,Error,},% |
---|
151 | sensitive=true,% |
---|
152 | morecomment=[l]{//},% |
---|
153 | morecomment=[s]{/*}{*/},% |
---|
154 | morestring=[b]',% |
---|
155 | morestring=[b]",% |
---|
156 | morestring=[s]{`}{`},% |
---|
157 | } |
---|
158 | |
---|
159 | % CFA programming language, based on ANSI C |
---|
160 | \lstdefinelanguage{CFA}[ANSI]{C}{ |
---|
161 | morekeywords={_Alignas,_Alignof,__alignof,__alignof__,asm,__asm,__asm__,_At,_Atomic,__attribute,__attribute__,auto, |
---|
162 | _Bool,catch,catchResume,choose,_Complex,__complex,__complex__,__const,__const__,disable,dtype,enable,__extension__, |
---|
163 | fallthru,finally,forall,ftype,_Generic,_Imaginary,inline,__label__,lvalue,_Noreturn,otype,restrict,_Static_assert, |
---|
164 | _Thread_local,throw,throwResume,trait,try,typeof,__typeof,__typeof__,}, |
---|
165 | moredelim=**[is][\color{red}]{`}{`}, % red highlighting of program text |
---|
166 | }% |
---|
167 | |
---|
168 | \lstset{ |
---|
169 | language=CFA, |
---|
170 | columns=flexible, |
---|
171 | basicstyle=\sf\relsize{-1}, |
---|
172 | tabsize=4, |
---|
173 | xleftmargin=\parindent, |
---|
174 | escapechar=@, |
---|
175 | mathescape=true, |
---|
176 | keepspaces=true, |
---|
177 | showstringspaces=false, |
---|
178 | showlines=true, |
---|
179 | aboveskip=6pt, |
---|
180 | belowskip=4pt, |
---|
181 | literate={\\`}{\raisebox{0.3ex}{\ttfamily\upshape \hspace*{-2pt}`}}1, % escape \`, otherwise used for red highlighting |
---|
182 | }% |
---|
183 | |
---|
184 | \makeatletter |
---|
185 | % replace/adjust listings characters that look bad in sanserif |
---|
186 | \lst@CCPutMacro |
---|
187 | \lst@ProcessOther{"22}{\lst@ttfamily{"}{\raisebox{0.3ex}{\ttfamily\upshape "}}} % replace double quote |
---|
188 | \lst@ProcessOther{"27}{\lst@ttfamily{'}{\raisebox{0.3ex}{\ttfamily\upshape '\hspace*{-2pt}}}} % replace single quote |
---|
189 | \lst@ProcessOther{"2D}{\lst@ttfamily{-}{\ttfamily\upshape -}} % replace minus |
---|
190 | \lst@ProcessOther{"3C}{\lst@ttfamily{<}{\texttt{<}}} % replace less than |
---|
191 | \lst@ProcessOther{"3E}{\lst@ttfamily{<}{\texttt{>}}} % replace greater than |
---|
192 | \lst@ProcessOther{"5E}{\raisebox{0.4ex}{$\scriptstyle\land\,$}} % replace circumflex |
---|
193 | \lst@ProcessOther{"5F}{\lst@ttfamily{\char95}{{\makebox[1.2ex][c]{\rule{1ex}{0.1ex}}}}} % replace underscore |
---|
194 | \lst@ProcessOther{"60}{\lst@ttfamily{`}{\raisebox{0.3ex}{\ttfamily\upshape \hspace*{-2pt}`}}} % replace backquote |
---|
195 | \lst@ProcessOther{"7E}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}} % replace tilde |
---|
196 | %\lst@ProcessOther{"7E}{\raisebox{-.4ex}[1ex][0pt]{\textasciitilde}} % lower tilde |
---|
197 | \@empty\z@\@empty % NECESSARY DO NOT REMOVE |
---|
198 | \makeatother |
---|
199 | |
---|
200 | % Local Variables: % |
---|
201 | % tab-width: 4 % |
---|
202 | % fill-column: 100 % |
---|
203 | % End: % |
---|