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

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

Andrew MMath: Switch from common.tex to cfalab.sty. Still work to do but it is almost everything I had before.

  • Property mode set to 100644
File size: 6.2 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 \colour 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\lstnewenvironment{cfa}[1][]{\lstset{language=CFA}\lstset{#1}}{}
63
64% \settextunderscore{(new|old)}
65% Redefines the underscore either as a new repersentation or the old one.
66% Not that some other packages (ex. hyperref) can override this. Set it up
67% after loading them.
68\let\cfalab@textunderscore@old=\textunderscore
69\newcommand\cfalab@textunderscore@new{%
70    \leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
71\newcommand\settextunderscore[1]{%
72    \renewcommand\textunderscore{\csuse{cfalab@textunderscore@#1}}}
73
74% The CFA listings language. Based off of ANCI C and including GCC extensions.
75% The UW dialect is the default (and only so far) dialect of the language.
76\lstdefinelanguage[UW]{CFA}[ANSI]{C}{
77    morekeywords={_Alignas, _Alignof, __alignof, __alignof__, asm, __asm,
78        __asm__, __attribute, __attribute__, auto, _Bool, catch, catchResume,
79        choose, _Complex, __complex, __complex__, __const, __const__,
80        coroutine, disable, dtype, enable, exception, __extension__,
81        fallthrough, fallthru, finally, __float80, float80, __float128,
82        float128, forall, ftype, generator, _Generic, _Imaginary, __imag,
83        __imag__, inline, __inline, __inline__, __int128, int128, __label__,
84        monitor, mutex, _Noreturn, one_t, or, otype, restrict, resume,
85        __restrict, __restrict__, __signed, __signed__, _Static_assert,
86        suspend, thread, _Thread_local, throw, throwResume, timeout, trait,
87        try, ttype, typeof, __typeof, __typeof__, virtual, __volatile,
88        __volatile__, waitfor, when, with, zero_t
89    },
90    moredirectives={defined,include_next},
91}
92\lstset{defaultdialect={[UW]CFA}}
93
94% The cfalab style defines some common settings useful in different languages.
95\lstdefinestyle{cfalab}{%
96    columns=fullflexible,
97    basicstyle=\linespread{0.9}\tt,
98    stringstyle=\tt,
99}
100
101% common.tex Compatablity ===================================================
102% Below this line is for compatability with the old common.tex file.
103
104\newcommand{\CFAStyle}{%
105  \lstset{
106    columns=fullflexible,
107    % reduce line spacing and use sanserif font
108    basicstyle=\linespread{0.9}\sf,
109    % use typewriter font
110    stringstyle=\tt,
111    tabsize=5,
112    % indent code to paragraph indentation
113    %xleftmargin=\parindentlnth,
114    % Allow ASCII characters in the range 128-255.
115    extendedchars=true,
116    % This allows you to use "math mode" to insert LaTeX into the code.
117    % Use \( and \) if you need to insert math mode inside that code.
118    escapechar=\$,
119    % LaTeX math escape in CFA code $...$
120    mathescape=false,
121    keepspaces=true,
122    % do not show spaces with cup
123    showstringspaces=false,
124    % show blank lines at end of code
125    showlines=true,
126    aboveskip=4pt,                          % spacing above/below code block
127    belowskip=0pt,
128    % numbering style
129    numberstyle=\footnotesize\sf,
130    % replace/adjust listing characters that look bad in sanserif
131    literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.75ex}{0.1ex}}}}1
132      {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
133      {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
134      {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2
135      {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2,
136  }
137}
138
139\newcommand{\abbrevFont}{\textit}           % set empty for no italics
140\@ifundefined{eg}{
141\newcommand{\EG}{\abbrevFont{e}.\abbrevFont{g}.}
142\newcommand*{\eg}{%
143    \@ifnextchar{,}{\EG}%
144        {\@ifnextchar{:}{\EG}%
145            {\EG,\xspace}}%
146}}{}%
147\@ifundefined{ie}{
148\newcommand{\IE}{\abbrevFont{i}.\abbrevFont{e}.}
149\newcommand*{\ie}{%
150    \@ifnextchar{,}{\IE}%
151        {\@ifnextchar{:}{\IE}%
152            {\IE,\xspace}}%
153}}{}%
154\@ifundefined{etc}{
155\newcommand{\ETC}{\abbrevFont{etc}}
156\newcommand*{\etc}{%
157    \@ifnextchar{.}{\ETC}%
158        {\ETC.\xspace}%
159}}{}%
160\@ifundefined{etal}{
161\newcommand{\ETAL}{\abbrevFont{et}~\abbrevFont{al}}
162\newcommand*{\etal}{%
163    \@ifnextchar{.}{\protect\ETAL}%
164        {\protect\ETAL.\xspace}%
165}}{}%
166\@ifundefined{viz}{
167\newcommand{\VIZ}{\abbrevFont{viz}}
168\newcommand*{\viz}{%
169    \@ifnextchar{.}{\VIZ}%
170        {\VIZ.\xspace}%
171}}{}%
172
173\endinput
Note: See TracBrowser for help on using the repository browser.