diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-09-04 11:20:29 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-09-04 11:20:29 +0200 |
commit | aa58464097897f0fdd1da9d0f6c0321cea2f4e54 (patch) | |
tree | 3c302684c00bceb42e6105d128b54fcb3569ea35 | |
parent | 7b34d0b0498b5e41cbe00dbeaca0688af86f4111 (diff) |
more example latex code
-rw-r--r-- | .vimrc | 12 | ||||
-rw-r--r-- | example.tex | 87 | ||||
-rw-r--r-- | projdoc.cls | 137 | ||||
-rw-r--r-- | sources.bib | 14 |
4 files changed, 245 insertions, 5 deletions
@@ -0,0 +1,12 @@ +" fix vimtex highlighting for \code{} +syntax match texCmdVerb "\\code\>\*\?" nextgroup=texVerbZoneInline +call vimtex#syntax#core#new_arg('texVerbZoneInline', { + \ 'contains': '', + \ 'matcher': 'start="{" end="}"' + \}) +" and \begin{codeblock} ... \end{codeblock} +call vimtex#syntax#core#new_env({ + \ 'name': 'codeblock', + \ 'region': 'texVerbZone', + \}) + diff --git a/example.tex b/example.tex index 843cf38..362ce29 100644 --- a/example.tex +++ b/example.tex @@ -1,4 +1,6 @@ \documentclass{projdoc} +% if the document compiles too slow (likely due to many/large images), try compiling +% with the [draft] option. this replaces all images with placeholders. \input{meta.tex} \title{Example Document} @@ -31,13 +33,30 @@ These don't show up in the table of contents by default \section{Figures and tables} -\Cref{fig:example-a} definitely shows something. +\Cref{fig:example-a} definitely shows something. Referencing multiple things at once +is neatly handled by cleveref: +\cref{fig:example-a,fig:example-b,fig:example-c,tab:gate-xor}. \begin{figure} \centering \includegraphics[width=8cm]{example-image-a} - \label{fig:example-a} \caption{This is the figure title} + \label{fig:example-a} % label must be placed AFTER caption +\end{figure} + +\begin{figure} + \begin{subfigure}{0.45\textwidth}% + \fitimg{\includegraphics{example-image-b}} + \caption{Example image B} + \label{fig:example-b} + \end{subfigure}% + \hfill + \begin{subfigure}{0.45\textwidth}% + \fitimg{\includegraphics{example-image-c}} + \caption{Example image C} + \label{fig:example-c} + \end{subfigure}% + \caption{Subfigures} \end{figure} \begin{table} @@ -55,9 +74,71 @@ These don't show up in the table of contents by default \end{tabular} % booktabs tables look very nice, but it seems the author hates vertical rules with % a burning passion. please avoid using vertical rules for consistency. - \label{tab:gate-xor} \caption{XOR-gate truth table} + \label{tab:gate-xor} \end{table} +\begin{table} + \begin{tabularx}{\linewidth}{lXr} + \toprule + left & & right\\ + \midrule + This table & fills all available & horizontal space\\ + \bottomrule + \end{tabularx} + \caption{Really wide table} +\end{table} + +\section{Other markup} + +\subsection{Fonts} + +The \code{\emph} command can be used to \emph{emphasize} (i.e.~italicize) text. +% Note the ~ (non-breaking space) after "i.e.". LaTeX inserts some extra negative +% space after a full stop, but since the full stop is used to denote an abbreviation +% we need to tell LaTeX to insert a regular space. This can also be achieved by using +% "\ ", though this allows LaTeX to break a line after the "i.e." which looks ugly in +% my opinion. + +The \code{\code} command can be used to insert inline code. + +The \code{codeblock} environment can be used to insert a code block: + +\begin{codeblock} +This is all included verbatim: \verb|asdf| \ $%!(*@#&)$ +\end{codeblock} + +\subsection{Lists} + +Unordered (bullet) list: + +\begin{itemize} + \item Foo + \item Bar + \item Baz +\end{itemize} + +Numbered list: + +\begin{enumerate} + \item Foo + \item Bar + \item Baz + \item \begin{enumerate} + \item These + \item Can + \item Be + \item Nested + \item And + \item \label{item:enum-nest-ref} Referenced + \end{enumerate} +\end{enumerate} + +(See \cref{item:enum-nest-ref}) + +\subsection{Citations} + +Citations are inserted using the \code{\autocite} command \autocite{rfc:3339}. + \end{document} diff --git a/projdoc.cls b/projdoc.cls index cc34f70..02e9542 100644 --- a/projdoc.cls +++ b/projdoc.cls @@ -12,6 +12,8 @@ \PassOptionsToPackage{english}{babel} \PassOptionsToPackage{noabbrev}{cleveref} \PassOptionsToPackage{nosort}{cleveref} +\PassOptionsToPackage{nameinlink}{cleveref} +\PassOptionsToPackage{obeyspaces}{url} % frequently used packages \RequirePackage{geometry} @@ -19,6 +21,8 @@ \RequirePackage{babel} \RequirePackage{siunitx} \RequirePackage{csquotes} +\RequirePackage{url} +\RequirePackage{fancyvrb} \RequirePackage{parskip} \RequirePackage{fontspec} \RequirePackage{tabularx} @@ -32,6 +36,11 @@ \RequirePackage{unicode-math} \RequirePackage{amsmath} \RequirePackage{cleveref} +\RequirePackage{adjustbox} +\RequirePackage{xparse} +\RequirePackage{ifdraft} +\RequirePackage{enumitem} +\RequirePackage{subcaption} % font style \setmainfont{TeX Gyre Schola} @@ -47,6 +56,69 @@ \bigskipamount=7mm \medskipamount=4mm +% section placement / appearance +\newlength{\sectionpenalty} +\newlength{\subsectionpenalty} +\newlength{\subsubsectionpenalty} +\setlength{\sectionpenalty}{0.4\textheight} +\setlength{\subsectionpenalty}{0.1\textheight} +\setlength{\subsubsectionpenalty}{0pt} +\def\penaltycheck#1{\ifdimgreater{#1}{0pt}{\needspace{#1}}{}} +\ifdraft{\def\penaltycheck#1{\relax}}{} +\makeatletter +\renewcommand\section{% + \@startsection{section}{1}% + {0pt}% + {1.50em}% + {1.50ex}% + {\penaltycheck{\sectionpenalty}\normalfont\bfseries\Large}% +} +\renewcommand\subsection{% + \@startsection{subsection}{2}% + {0pt}% + {1.25em}% + {1.25ex}% + {\penaltycheck{\subsectionpenalty}\normalfont\bfseries\large}% +} +\renewcommand\subsubsection{% + \@startsection{subsubsection}{2}% + {0pt}% + {1.00em}% + {1.00ex}% + {\penaltycheck{\subsubsectionpenalty}\normalfont\bfseries\normalsize}% +} +\makeatother + +% default tight list spacing +\makeatletter +\newlength{\style@parsep} +\newlength{\style@itemsep} +\newlength{\style@itemizemargin} +\setlength{\style@parsep}{1mm} +\setlength{\style@itemsep}{1mm} +\setlength{\style@itemizemargin}{2mm} +\setlist{ + topsep=\dimexpr\style@itemizemargin-\parskip\relax, + itemsep=\dimexpr\style@itemsep-\style@parsep\relax, + parsep=\style@parsep, +} +\makeatother + +% create a label using \customlabel[<creftype>]{<refname>}{<reftext>} that displays +% <reftext> when \ref{<refname>} is used, or <creftype> <reftext> when +% \cref{<refname>} is used +\makeatletter +\NewDocumentCommand{\customlabel}{omm}{% + \begingroup + \cref@constructprefix{#1}{\cref@result}% + \protected@edef\@currentlabel{#3}% + \protected@edef\@currentlabelname{#3}% + \protected@edef\cref@currentlabel{[#1][][\cref@result]#3} + \label[#1]{#2}% + \endgroup +} +\makeatother + % \maketitle format \makeatletter \let\@project\relax @@ -98,14 +170,38 @@ \def\fps@table{H} \makeatother -% always start with title page -\AtBeginDocument{ +% bibliography +\usepackage[ + backend=biber, + bibencoding=utf8, + style=iso-numeric, + % Technically, Avans University of Applied Sciences requires that we always use APA + % style references, but this often results in ugly citations when working with + % technical or online resources. At the end of the day, the bibliography is there + % to prove we didn't plagiarize or make shit up, so ISO 690 is *probably* fine. + autocite=plain, +]{biblatex} +\addbibresource{sources.bib} + +% default document header/trailer +\makeatletter +\def\projdoc@header{ + % start with title page \clearpage \begin{titlepage} \maketitle \thispagestyle{empty} \end{titlepage} } +\newbool{projdoc@cited} +\apptocmd{\abx@aux@cite}{\global\booltrue{projdoc@cited}}{}{} +\def\projdoc@trailer{ + % end with bibliography (if citations used) + \ifbool{projdoc@cited}{\printbibliography}{}% +} +\AtBeginDocument{\projdoc@header} +\AtEndDocument{\projdoc@trailer} +\makeatother % store figure/table count in macros \makeatletter @@ -119,7 +215,44 @@ % generate table of contents, figures, tables \def\tablestables{% \tableofcontents% + \label{sec:toc}% \ifnumgreater{\figurecount}{0}{\listoffigures}{}% + \label{sec:lof}% \ifnumgreater{\tablecount}{0}{\listoftables}{}% + \label{sec:lot}% +} + +% code +\DeclareUrlCommand\code{% + \urlstyle{tt}% + \def\codebreak{\discretionary{\hbox{~\textbackslash{}}}{\hbox{~~}}{}}% + \def\UrlSpecials{% + \do\/{\hbox{/}\codebreak}% + \do\_{\hbox{\_}\codebreak}% + \do\ {\hbox{\ }\codebreak}% + \do\-{\hbox{-}\codebreak}% + }% + \def\UrlNoBreaks{% + \do\+% + \do\.% + \do\[% + \do\]% + }% + \def\UrlLeft{\hbox{\,}}% + \def\UrlRight{\hbox{\,}}% +} +\DefineVerbatimEnvironment{codeblock}{Verbatim}{ + tabsize=2, + obeytabs, +} + +% scale down image if it exceeds page margins +\newcommand{\fitimg}[1]{% + \adjustbox{max width=\linewidth}{#1}% +} + +% adjust scale for puml diagrams +\newcommand{\includepumldiag}[1]{% + \fitimg{\includegraphics[scale=0.6]{#1}}% } diff --git a/sources.bib b/sources.bib index e69de29..b088784 100644 --- a/sources.bib +++ b/sources.bib @@ -0,0 +1,14 @@ +% bible: <https://tug.ctan.org/info/biblatex-cheatsheet/biblatex-cheatsheet.pdf> + +@techreport{rfc:3339, + author = {G. Klyne and C. Newman}, + title = {Date and Time on the Internet: Timestamps}, + url = {https://www.rfc-editor.org/rfc/rfc3339}, + urldate = {2023-01-03}, + date = {2002-07}, + type = {RFC}, + number = 3339, + publisher = {RFC Editor}, + institution = {RFC Editor}, +} + |