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

Last change on this file since 9476549 was d02e547, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Andrew MMath: Improvements to implement figures.

  • Property mode set to 100644
File size: 7.1 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      \def\code#1#2{#2}
43    }
44  }{}
45}
46
47% \colour{<colour>}{<text>}
48% Just \color but using the LaTeX style instead of TeX style command.
49\newcommand*\colour[2]{{\color{#1}#2}}
50
51% \code{<language>}{<code>}
52% Use the listings package to format the snipit of <code> in <language>.
53\newrobustcmd*\code[2]{\lstinline[language=#1]{#2}}
54
55% \begin{cfa}[<options>]
56% \end{cfa}
57% Use the listings package to format a block of CFA code.
58% Extra listings options can be passed in as an optional argument.
59\lstnewenvironment{cfa}[1][]{\lstset{language=CFA}\lstset{#1}}{}
60
61% \settextunderscore{(new|old)}
62% Redefines the underscore either as a new repersentation or the old one.
63% Not that some other packages (ex. hyperref) can override this. Set it up
64% after loading them.
65\let\cfalab@textunderscore@old=\textunderscore
66\newcommand\cfalab@textunderscore@new{%
67    \leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
68\newcommand\settextunderscore[1]{%
69    \renewcommand\textunderscore{\csuse{cfalab@textunderscore@#1}}}
70
71% The CFA listings language. Based off of ANCI C and including GCC extensions.
72% The UW dialect is the default (and only so far) dialect of the language.
73\lstdefinelanguage[UW]{CFA}[ANSI]{C}{
74    morekeywords={_Alignas, _Alignof, __alignof, __alignof__, asm, __asm,
75        __asm__, __attribute, __attribute__, auto, _Bool, catch, catchResume,
76        choose, _Complex, __complex, __complex__, __const, __const__,
77        coroutine, disable, dtype, enable, exception, __extension__,
78        fallthrough, fallthru, finally, __float80, float80, __float128,
79        float128, forall, ftype, generator, _Generic, _Imaginary, __imag,
80        __imag__, inline, __inline, __inline__, __int128, int128, __label__,
81        monitor, mutex, _Noreturn, one_t, or, otype, restrict, resume,
82        __restrict, __restrict__, __signed, __signed__, _Static_assert,
83        suspend, thread, _Thread_local, throw, throwResume, timeout, trait,
84        try, ttype, typeof, __typeof, __typeof__, virtual, __volatile,
85        __volatile__, waitfor, when, with, zero_t
86    },
87    moredirectives={defined,include_next},
88}
89\lstset{defaultdialect={[UW]CFA}}
90
91% Create an internal paragraph indent amount. This is used internally to
92% mimic the standard indent even when it has been overriden in the document.
93\newlength\cfalab@parindent
94\deflength\cfalab@parindent{\parindent}
95
96% The cfacommon style has many useful defaults for CFA and other types of
97% code. Use the listings option "style=cfacommon" to load them.
98\lstdefinestyle{cfacommon}{
99  columns=fullflexible,
100  basicstyle=\linespread{0.9}\sf,
101  stringstyle=\tt,
102  tabsize=5,
103  % Indent code to paragraph indentation.
104  xleftmargin=\cfalab@parindent,
105  % Allow ASCII characters in the range 128-255.
106  extendedchars=true,
107  % This allows you to use "math mode" to insert LaTeX into the code.
108  % Use \( and \) if you need to insert math mode inside that code.
109  escapechar=\$,
110  % Disable LaTeX math escape in CFA code $...$
111  mathescape=false,
112  keepspaces=true,
113  % Do not show spaces with cup.
114  showstringspaces=false,
115  % Show blank lines at end of code.
116  showlines=true,
117  % Spacing above/below code block.
118  aboveskip=4pt,belowskip=0pt,
119  numberstyle=\footnotesize\sf,
120  % Replace/adjust listing characters that look bad in sanserif.
121  literate={-}{\makebox[1ex][c]{\raisebox{0.7ex}{\rule{0.75ex}{0.1ex}}}}1
122    {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1
123    {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1
124    {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2
125    {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2,
126}
127
128% \snake{<identifier>}
129% Improves writing of snake case (or any convention that uses _) by allowing
130% line breaks after _. Disables commands inside the block and formats the
131% identifier to look like code.
132\newcommand*\snake[1]{\snakefont{\expandafter\snake@next\detokenize{#1}\@nil}}
133
134% \snakefont{<text>}
135% Command used by \snake, you may renew the command to change its formating.
136\newcommand*\snakefont[1]{\texttt{#1}}
137
138% Thanks Manuel of TeX Stack exchange. (I got the base pattern from one of
139% their answers.) Note: \@nil should never be defined.
140\newcommand*\snake@next[1]{\ifx\@nil#1\else
141  \expandafter\ifx\string_#1\string_\allowbreak\else#1\fi
142  \expandafter\snake@next\fi
143}
144
145% These somehow control how much of a page can be a floating element before
146% the float is forced onto its own page.   
147\renewcommand{\topfraction}{0.8}
148\renewcommand{\bottomfraction}{0.8}
149\renewcommand{\floatpagefraction}{0.8}
150% Sort of the reverse, I think it is the minimum amount of text that can
151% be on a page before its all removed. (0 for always fix what you can.)
152\renewcommand{\textfraction}{0.0}
153
154% common.tex Compatablity ===================================================
155% Below this line is for compatability with the old common.tex file.
156
157% Backwards compatable way to activate the cfacommon style.
158\newcommand{\CFAStyle}{\lstset{style=cfacommon}}
159
160% A couple of abbreviations are provided. Just ones someone liked.
161%
162% Abbreviation formatting commands (renew to customize):
163\newcommand{\abbrevFont}{\textit}
164%
165% Abbreviations that, if not followed by a comma or colon, add a comma.
166\newrobustcmd*\cfalab@abbrev@comma{%
167  \@ifnextchar{,}{}{\@ifnextchar{:}{}{,\xspace}}}
168\providerobustcmd*\eg{\abbrevFont{e}.\abbrevFont{g}.\cfalab@abbrev@comma}
169\providerobustcmd*\ie{\abbrevFont{i}.\abbrevFont{e}.\cfalab@abbrev@comma}
170%
171% Abbreviations that, if not followed by a period, add a period.
172\newrobustcmd*\cfalab@abbrev@period{\@ifnextchar{.}{}{.\xspace}}
173\providerobustcmd*\etc{\abbrevFont{etc}\cfalab@abbrev@period}
174\providerobustcmd*\etal{\abbrevFont{et}~\abbrevFont{al}\cfalab@abbrev@period}
175\providerobustcmd*\viz{\abbrevFont{viz}\cfalab@abbrev@period}
176
177\endinput
Note: See TracBrowser for help on using the repository browser.