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

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since edc6ea2 was edc6ea2, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Andrew MMath: LaTeX clean-up. Went through existing to make some of the examples more managable.

  • Property mode set to 100644
File size: 6.3 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% The cfalab style defines some common settings useful in different languages.
97\lstdefinestyle{cfalab}{%
98    columns=fullflexible,
99    basicstyle=\linespread{0.9}\tt,
100    stringstyle=\tt,
101}
102
103% common.tex Compatablity ===================================================
104% Below this line is for compatability with the old common.tex file.
105
106\newcommand{\CFAStyle}{%
107  \lstset{
108    columns=fullflexible,
109    % reduce line spacing and use sanserif font
110    basicstyle=\linespread{0.9}\sf,
111    % use typewriter font
112    stringstyle=\tt,
113    tabsize=5,
114    % indent code to paragraph indentation
115    %xleftmargin=\parindentlnth,
116    % Allow ASCII characters in the range 128-255.
117    extendedchars=true,
118    % This allows you to use "math mode" to insert LaTeX into the code.
119    % Use \( and \) if you need to insert math mode inside that code.
120    escapechar=\$,
121    % LaTeX math escape in CFA code $...$
122    mathescape=false,
123    keepspaces=true,
124    % do not show spaces with cup
125    showstringspaces=false,
126    % show blank lines at end of code
127    showlines=true,
128    % spacing above/below code block
129    aboveskip=4pt,
130    belowskip=0pt,
131    % numbering style
132    numberstyle=\footnotesize\sf,
133    % replace/adjust listing characters that look bad in sanserif
134    literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.75ex}{0.1ex}}}}1
135      {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
136      {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
137      {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2
138      {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2,
139  }
140}
141
142% A couple of abbreviations are provided. Just ones someone liked.
143%
144% Abbreviation formatting commands (renew to customize):
145\newcommand{\abbrevFont}{\textit}
146%
147% Abbreviations that, if not followed by a comma or colon, add a comma.
148\newrobustcmd*\cfalab@abbrev@comma{%
149  \@ifnextchar{,}{}{\@ifnextchar{:}{}{,\xspace}}}
150\providerobustcmd*\eg{\abbrevFont{e}.\abbrevFont{g}.\cfalab@abbrev@comma}
151\providerobustcmd*\ie{\abbrevFont{i}.\abbrevFont{e}.\cfalab@abbrev@comma}
152%
153% Abbreviations that, if not followed by a period, add a period.
154\newrobustcmd*\cfalab@abbrev@period{\@ifnextchar{.}{}{.\xspace}}
155\providerobustcmd*\etc{\abbrevFont{etc}\cfalab@abbrev@period}
156\providerobustcmd*\etal{\abbrevFont{et}~\abbrevFont{al}\cfalab@abbrev@period}
157\providerobustcmd*\viz{\abbrevFont{viz}\cfalab@abbrev@period}
158
159\endinput
Note: See TracBrowser for help on using the repository browser.