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 | % \code{<language>}{<code>} |
---|
51 | % Use the listings package to format the snipit of <code> in <language>. |
---|
52 | \newrobustcmd*\code[2]{\lstinline[language=#1]{#2}} |
---|
53 | |
---|
54 | % \begin{cfa}[<options>] |
---|
55 | % \end{cfa} |
---|
56 | % Use the listings package to format a block of CFA code. |
---|
57 | % Extra listings options can be passed in as an optional argument. |
---|
58 | \lstnewenvironment{cfa}[1][]{\lstset{language=CFA}\lstset{#1}}{} |
---|
59 | |
---|
60 | % \settextunderscore{(new|old)} |
---|
61 | % Redefines the underscore either as a new repersentation or the old one. |
---|
62 | % Not that some other packages (ex. hyperref) can override this. Set it up |
---|
63 | % after loading them. |
---|
64 | \let\cfalab@textunderscore@old=\textunderscore |
---|
65 | \newcommand\cfalab@textunderscore@new{% |
---|
66 | \leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}} |
---|
67 | \newcommand\settextunderscore[1]{% |
---|
68 | \renewcommand\textunderscore{\csuse{cfalab@textunderscore@#1}}} |
---|
69 | |
---|
70 | % The CFA listings language. Based off of ANCI C and including GCC extensions. |
---|
71 | % The UW dialect is the default (and only so far) dialect of the language. |
---|
72 | \lstdefinelanguage[UW]{CFA}[ANSI]{C}{ |
---|
73 | morekeywords={_Alignas, _Alignof, __alignof, __alignof__, asm, __asm, |
---|
74 | __asm__, __attribute, __attribute__, auto, _Bool, catch, catchResume, |
---|
75 | choose, _Complex, __complex, __complex__, __const, __const__, |
---|
76 | coroutine, disable, dtype, enable, exception, __extension__, |
---|
77 | fallthrough, fallthru, finally, __float80, float80, __float128, |
---|
78 | float128, forall, ftype, generator, _Generic, _Imaginary, __imag, |
---|
79 | __imag__, inline, __inline, __inline__, __int128, int128, __label__, |
---|
80 | monitor, mutex, _Noreturn, one_t, or, otype, restrict, resume, |
---|
81 | __restrict, __restrict__, __signed, __signed__, _Static_assert, |
---|
82 | suspend, thread, _Thread_local, throw, throwResume, timeout, trait, |
---|
83 | try, ttype, typeof, __typeof, __typeof__, virtual, __volatile, |
---|
84 | __volatile__, waitfor, when, with, zero_t |
---|
85 | }, |
---|
86 | moredirectives={defined,include_next}, |
---|
87 | } |
---|
88 | \lstset{defaultdialect={[UW]CFA}} |
---|
89 | |
---|
90 | % Create an internal paragraph indent amount. This is used internally to |
---|
91 | % mimic the standard indent even when it has been overriden in the document. |
---|
92 | \newlength\cfalab@parindent |
---|
93 | \deflength\cfalab@parindent{\parindent} |
---|
94 | |
---|
95 | % The cfacommon style has many useful defaults for CFA and other types of |
---|
96 | % code. Use the listings option "style=cfacommon" to load them. |
---|
97 | \lstdefinestyle{cfacommon}{ |
---|
98 | columns=fullflexible, |
---|
99 | basicstyle=\linespread{0.9}\sf, |
---|
100 | stringstyle=\tt, |
---|
101 | tabsize=5, |
---|
102 | % Indent code to paragraph indentation. |
---|
103 | xleftmargin=\cfalab@parindent, |
---|
104 | % Allow ASCII characters in the range 128-255. |
---|
105 | extendedchars=true, |
---|
106 | % This allows you to use "math mode" to insert LaTeX into the code. |
---|
107 | % Use \( and \) if you need to insert math mode inside that code. |
---|
108 | escapechar=\$, |
---|
109 | % Disable LaTeX math escape in CFA code $...$ |
---|
110 | mathescape=false, |
---|
111 | keepspaces=true, |
---|
112 | % Do not show spaces with cup. |
---|
113 | showstringspaces=false, |
---|
114 | % Show blank lines at end of code. |
---|
115 | showlines=true, |
---|
116 | % Spacing above/below code block. |
---|
117 | aboveskip=4pt,belowskip=0pt, |
---|
118 | numberstyle=\footnotesize\sf, |
---|
119 | % Replace/adjust listing characters that look bad in sanserif. |
---|
120 | literate={-}{\makebox[1ex][c]{\raisebox{0.7ex}{\rule{0.75ex}{0.1ex}}}}1 |
---|
121 | {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1 |
---|
122 | {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1 |
---|
123 | {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 |
---|
124 | {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2, |
---|
125 | } |
---|
126 | |
---|
127 | % common.tex Compatablity =================================================== |
---|
128 | % Below this line is for compatability with the old common.tex file. |
---|
129 | |
---|
130 | % Backwards compatable way to activate the cfacommon style. |
---|
131 | \newcommand{\CFAStyle}{\lstset{style=cfacommon}} |
---|
132 | |
---|
133 | % A couple of abbreviations are provided. Just ones someone liked. |
---|
134 | % |
---|
135 | % Abbreviation formatting commands (renew to customize): |
---|
136 | \newcommand{\abbrevFont}{\textit} |
---|
137 | % |
---|
138 | % Abbreviations that, if not followed by a comma or colon, add a comma. |
---|
139 | \newrobustcmd*\cfalab@abbrev@comma{% |
---|
140 | \@ifnextchar{,}{}{\@ifnextchar{:}{}{,\xspace}}} |
---|
141 | \providerobustcmd*\eg{\abbrevFont{e}.\abbrevFont{g}.\cfalab@abbrev@comma} |
---|
142 | \providerobustcmd*\ie{\abbrevFont{i}.\abbrevFont{e}.\cfalab@abbrev@comma} |
---|
143 | % |
---|
144 | % Abbreviations that, if not followed by a period, add a period. |
---|
145 | \newrobustcmd*\cfalab@abbrev@period{\@ifnextchar{.}{}{.\xspace}} |
---|
146 | \providerobustcmd*\etc{\abbrevFont{etc}\cfalab@abbrev@period} |
---|
147 | \providerobustcmd*\etal{\abbrevFont{et}~\abbrevFont{al}\cfalab@abbrev@period} |
---|
148 | \providerobustcmd*\viz{\abbrevFont{viz}\cfalab@abbrev@period} |
---|
149 | |
---|
150 | \endinput |
---|