source: doc/theses/andrew_beach_MMath/cfalab.sty @ 9d7e5cb

arm-ehenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 9d7e5cb was 9d7e5cb, checked in by Andrew Beach <ajbeach@…>, 19 months ago

Andrew MMath: First draft of the latest round of fixes to implement complete. More will be needed.

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