source: doc/theses/andrew_beach_MMath/cfalab.sty @ c1136c56

arm-ehjacob/cs343-translationnew-ast-unique-expr
Last change on this file since c1136c56 was c1136c56, checked in by Andrew Beach <ajbeach@…>, 6 months ago

Andrew MMath: \CFAStyle now uses an actual listings style.

  • Property mode set to 100644
File size: 6.4 KB
Line 
1% Package for CFA Research Lab.
2%
3% Made by combining and updating various macro files people had made.
4%
5% Internal commands are prefixed with "\cfalab@".
6
7% I don't know what the oldest LaTeX2e version with everything needed is.
8\NeedsTeXFormat{LaTeX2e}
9\ProvidesPackage{cfalab}[2020/03/24 v0.1 CFA Laboratory LaTeX Tools]
10
11% Other packages required.
12%
13% Access to new basic LaTeX tools and other low level commands.
14\RequirePackage{etoolbox}
15% Code formatting tools and environments.
16\RequirePackage{listings}
17% Automatically adds spaces.
18\RequirePackage{xspace}
19% Improved reference tools.
20\RequirePackage[nospace]{varioref}
21
22% Symbols: All symbols are zero argument robust commands with special rules
23% about the space following the c.s. token. Normally the space might be
24% re-added according to the rules of the xspace package. They may be followed
25% by a star (which the command will consume) to disable this behaviour.
26
27% \newsymbolcmd{<command>}{<replacement text>}
28% Defines <command> to be a symbol that has the given <replacement text>.
29\newrobustcmd*\newsymbolcmd[2]{\newrobustcmd{#1}{\cfalab@symbol{#2}}}
30\def\cfalab@symbol#1{\@ifnextchar*{#1\cfalab@eatstar}{#1\xspace}}
31\def\cfalab@eatstar*{}
32
33% Cforall with the forall symbol.
34\newsymbolcmd\CFA{\textsf{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}}
35% C++ with kerning. (No standard number support.)
36\newsymbolcmd\Cpp{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}}
37
38% This is executed very early in the \begin{document} code, before the
39% document's contents but after packages are loaded.
40\AtEndPreamble{
41  \@ifpackageloaded{hyperref}{
42    % Convert symbols to pdf compatable forms when required.
43    \pdfstringdefDisableCommands{
44      \def\CFA{CFA}
45      \def\Cpp{C++}
46      \def\lstinline{}
47    }
48  }{}
49}
50
51% \colour{<colour>}{<text>}
52% Just \color but using the LaTeX style instead of TeX style command.
53\newcommand*\colour[2]{{\color{#1}#2}}
54
55% \code*{<code>}
56% Use the listings package to format a snipit of <code>.
57\newrobustcmd*\codeCFA[1]{\lstinline[language=CFA]{#1}}
58\newrobustcmd*\codeC[1]{\lstinline[language=C]{#1}}
59\newrobustcmd*\codeCpp[1]{\lstinline[language=C++]{#1}}
60\newrobustcmd*\codePy[1]{\lstinline[language=Python]{#1}}
61
62% Use the listings package to format a block of CFA code.
63% Extra listings options can be passed in as an optional argument.
64\lstnewenvironment{cfa}[1][]{\lstset{language=CFA}\lstset{#1}}{}
65
66% \settextunderscore{(new|old)}
67% Redefines the underscore either as a new repersentation or the old one.
68% Not that some other packages (ex. hyperref) can override this. Set it up
69% after loading them.
70\let\cfalab@textunderscore@old=\textunderscore
71\newcommand\cfalab@textunderscore@new{%
72    \leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
73\newcommand\settextunderscore[1]{%
74    \renewcommand\textunderscore{\csuse{cfalab@textunderscore@#1}}}
75
76% The CFA listings language. Based off of ANCI C and including GCC extensions.
77% The UW dialect is the default (and only so far) dialect of the language.
78\lstdefinelanguage[UW]{CFA}[ANSI]{C}{
79    morekeywords={_Alignas, _Alignof, __alignof, __alignof__, asm, __asm,
80        __asm__, __attribute, __attribute__, auto, _Bool, catch, catchResume,
81        choose, _Complex, __complex, __complex__, __const, __const__,
82        coroutine, disable, dtype, enable, exception, __extension__,
83        fallthrough, fallthru, finally, __float80, float80, __float128,
84        float128, forall, ftype, generator, _Generic, _Imaginary, __imag,
85        __imag__, inline, __inline, __inline__, __int128, int128, __label__,
86        monitor, mutex, _Noreturn, one_t, or, otype, restrict, resume,
87        __restrict, __restrict__, __signed, __signed__, _Static_assert,
88        suspend, thread, _Thread_local, throw, throwResume, timeout, trait,
89        try, ttype, typeof, __typeof, __typeof__, virtual, __volatile,
90        __volatile__, waitfor, when, with, zero_t
91    },
92    moredirectives={defined,include_next},
93}
94\lstset{defaultdialect={[UW]CFA}}
95
96% Create an internal paragraph indent amount. This is used internally to
97% mimic the standard indent even when it has been overriden in the document.
98\newlength\cfalab@parindent
99\deflength\cfalab@parindent{\parindent}
100
101% The cfacommon style has many useful defaults for CFA and other types of
102% code. Use the listings option "style=cfacommon" to load them.
103\lstdefinestyle{cfacommon}{
104  columns=fullflexible,
105  basicstyle=\linespread{0.9}\sf,
106  stringstyle=\tt,
107  tabsize=5,
108  % Indent code to paragraph indentation.
109  xleftmargin=\cfalab@parindent,
110  % Allow ASCII characters in the range 128-255.
111  extendedchars=true,
112  % This allows you to use "math mode" to insert LaTeX into the code.
113  % Use \( and \) if you need to insert math mode inside that code.
114  escapechar=\$,
115  % Disable LaTeX math escape in CFA code $...$
116  mathescape=false,
117  keepspaces=true,
118  % Do not show spaces with cup.
119  showstringspaces=false,
120  % Show blank lines at end of code.
121  showlines=true,
122  % Spacing above/below code block.
123  aboveskip=4pt,belowskip=0pt,
124  numberstyle=\footnotesize\sf,
125  % Replace/adjust listing characters that look bad in sanserif.
126  literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.75ex}{0.1ex}}}}1
127    {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
128    {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
129    {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2
130    {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2,
131}
132
133% common.tex Compatablity ===================================================
134% Below this line is for compatability with the old common.tex file.
135
136% Backwards compatable way to activate the cfacommon style.
137\newcommand{\CFAStyle}{\lstset{style=cfacommon}}
138
139% A couple of abbreviations are provided. Just ones someone liked.
140%
141% Abbreviation formatting commands (renew to customize):
142\newcommand{\abbrevFont}{\textit}
143%
144% Abbreviations that, if not followed by a comma or colon, add a comma.
145\newrobustcmd*\cfalab@abbrev@comma{%
146  \@ifnextchar{,}{}{\@ifnextchar{:}{}{,\xspace}}}
147\providerobustcmd*\eg{\abbrevFont{e}.\abbrevFont{g}.\cfalab@abbrev@comma}
148\providerobustcmd*\ie{\abbrevFont{i}.\abbrevFont{e}.\cfalab@abbrev@comma}
149%
150% Abbreviations that, if not followed by a period, add a period.
151\newrobustcmd*\cfalab@abbrev@period{\@ifnextchar{.}{}{.\xspace}}
152\providerobustcmd*\etc{\abbrevFont{etc}\cfalab@abbrev@period}
153\providerobustcmd*\etal{\abbrevFont{et}~\abbrevFont{al}\cfalab@abbrev@period}
154\providerobustcmd*\viz{\abbrevFont{viz}\cfalab@abbrev@period}
155
156\endinput
Note: See TracBrowser for help on using the repository browser.