--- tags: seemoo, master --- # SEEMOO Thesis Template Tips & Tricks This a collection of tips, workarounds and fixes for the SEEMOO thesis template which is based on `classicthesis`. [toc] ## Notes and ToDos :::info Idee von Tanja :wink: ::: The following adds the ability to produce colorful boxes for todos and other notes. ### Code ```tex \definecolor{SEEMOO}{HTML}{f25c19} \newcommand{\todo}[2][]{% \IfStrEq{#1}{lowprio}{% \definecolor{bg}{named}{Goldenrod}}{% \IfStrEq{#1}{other}{% \definecolor{bg}{named}{VioletRed}}{% \IfStrEq{#1}{}{% \definecolor{bg}{named}{SEEMOO}}{% \definecolor{bg}{named}{#1} }% }% }% \begin{center} \vspace{-0.5em} \colorbox{bg}{\parbox{0.98\textwidth}{\sffamily{#2}}}% \end{center} } \newcommand{\note}[2][PUT-YOUR-SUPERVISOR-NAME-AS-FALLBACK-HERE]{\todo[other]{\textbf{#1}: #2}} ``` ### Usage ```tex \todo{This is the default ToDo with an orange background.} \todo[lowprio]{This is a ToDo with low priority with a yellow background.} \note{This is a note from your supervisor with a pink background and the name prepended.} \note[Chuck]{This is a note from Chuck with a pink background and his name prepended.} ``` ## Prevent overfull bibliography entries Often, the bibliography entries are wider than the text column. This can be avoided by adjusting the following in `Bibloography.tex`. ```tex \sloppy \printbibliography[heading=bibintoc] \fussy ``` `\sloppy` allows more space between words, `\fussy` is the default setting which is reverted after the bibliography. ## `minted` instead of `listings` `minted` allows more fancy code highlighting. ### Make *List of Listings* work 1. Comment everything related to `listings` in `classicthesis-config.tex` 2. Add the following to `classicthesis-config.tex` at the beginning of `% 3. Loading some handy packages` ```tex \usepackage[titles]{tocloft} \newlistof{listing}{lol}{List of Listings} \usepackage[chapter,newfloat]{minted} \newenvironment{code}{\captionsetup{type=listing}}{} \SetupFloatingEnvironment{listing}{% name={Listing}, fileext=lol} ``` 3. Adjust `FrontBackMatter/Content.tex`: replace `\lstlistoflistings` with `\listoflistings` Now you can add your listings like the following: ```tex \begin{listing}[h] \begin{minted}{C} #include <stdio.h> int main() { printf("Hello World\n"); return 0; } \end{minted} \caption[Greeting]{Greeting the word in C.} \label{lst:greeting-c} \end{listing} ``` ### TeXstudio `minted` uses the Python lib `pygments` to format the code so you need to allow the LaTeX compiler to use it. That can be done for TeXstudio with `% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]s` at the beginning of your `Thesis.tex`. ## Default styles Some default styles for minted might be the following: ```tex % Borrowed from https://tex.stackexchange.com/a/406872 % to use the current font size for mintedinline and \small for all other minted \makeatletter \newcommand{\currentfontsize}{\fontsize{\f@size}{\f@baselineskip}\selectfont} \makeatother \setminted{fontsize=\small} % smaller fontsize for listings \setmintedinline{fontsize=\currentfontsize} % for code in line, use the current fontsize \setminted{breaklines=true} % allow line breaks (shown by an arrow) \setminted{frame=lines} % lines at top and bottom of every listing \setminted{framerule=0.6pt % width of these lines \setminted{framesep=8pt} % more space \setminted{linenos} % display line numbers \setminted{tabsize=2} % make tabs smaller ``` <!-- ## Break long urls You might want to use `\usepackage{breakurl}` --> ## Use custom float for listings lstlisting has some drawbacks when it comes to captions. First, labels set via lstlisting are not proposed by TexStudio. Second, listings composed of various calls to \lstlisting or \lstinputlisting appear as seperate entries in the list of listings and caption anchors don't point to the top of the figure. A solution to this is to use the *float* package. That can be used to easily create custom float environments. One for listings can be defined as follows: ```tex \usepackage{float} \newfloat{lstfloat}{htbp}{lop} % Define float name, default positioning options and name of the tex log file used for this \floatname{lstfloat}{Listing} % Define title name used in captions (e.g. "Listing 1: Caption text.") \def\lstfloatautorefname{listing} % Needed for hyperref/auroref \crefalias{lstfloat}{listing} % Needed for cleverref ``` A new float can then be created like any other float environment: ```tex \begin{lstfloat}[options] Content goes here \end{lstfloat} ``` Now, to fit it properly in the list of listings, replace the original one produced by lstlistings \lstlistoflistings command: ```tex % Comment out original list of listing: %\pdfbookmark[1]{\lstlistlistingname}{lol} %\lstlistoflistings \begingroup \addto\captionsamerican{\renewcommand{\figurename}{Listings}} % Rename float titles. Make sure you choose the correct language here. \pdfbookmark[1]{List of Listings}{lop} % Set bookmark in pdf \listof{lstfloat}{List of Listings} % actual list of listings \endgroup ``` :::info NOTE: The \addto\captionsamerican stuff is necessary to prefix the entries with "Listing X:" instead of "Figure X:". If you use another language in babel, choose \captionsYOURLANGUAGE (e.g. \captionsenglish) instead. Checkout the log file "Thesis.lop" to see this. ::: ## Captions outside of float Sometimes it can be handy to define a caption outside of a float. That can be done with the *caption* package using the \captionof command. The first parameter is the float environment you want to set the caption for. Example: ```tex \captionof{figure}{Example text outside of a float environment.} \label{fig:figure-outside-of-float} ``` A downside of this approach is that the hyperref anchor is at the caption and not at the beginning of the actual thing you want the caption for (i.e. you don't see your figure but only the caption at the top of the page when you click the link) ## Spelling and grammar checks - [LanguageTool](https://www.languagetool.org/) in TeXstudio - [TeXtidote](https://github.com/sylvainhalle/textidote) ## PDF/A-1b Compliance :::info Using the following information costs you one beer :beer: ::: The digital submission of the thesis in TUbama must be PDF/A-1b compliant (ISO standard for digital document archiving). This is sucking crap in LaTeX (and possibly everywhere else). What you have to do create the holy grail PDF version of your thesis: - ensure that all included PDFs are in RGB color mode, eventually even with `sRGB_IEC61966-2-1_black_scaled.icc` color profile - move the following **before** `\documentclass` and ensure that all lines like in the following example are present (`\Publisher`, I'm looking at you). Also you have to use `\RequirePackage` instead of `\usepackage` ```latex \RequirePackage{filecontents} \begin{filecontents*}{\jobname.xmpdata} \Title{\myTitle} \Author{\myName} \Copyright{\copyright\ \myYear\ \myName} \Keywords{Keyword1 \sep Keyword} \Subject{\myAbstract} \Publisher{\myDepartment, \myFaculty, \myUni} \end{filecontents*} ``` - for this, it is useful to move all personal data definitions from `classicthesis-config.tex` to a dedicated file and include this **before** the stuff above - Move the following directly **after** `\documentclass` ```latex \PassOptionsToPackage{dvipsnames}{xcolor} \usepackage[a-1b]{pdfx} ``` - Tip: these lines are originally located at different places - You can remove all `\pdf*` keys from `\hypersetup` in `classicalthesis-config.tex` since they are ignored due to pdfx to get less warnings (No warnings are not possible anyway, because ${\displaystyle \mathrm {L\!\!^{{}_{A}}\!\!\!\!\!\;\;T\!_{\displaystyle E}\!X}}$) - **pray** :pray: You can now check the compliance of your PDF using the open-source tool [veraPDF](https://verapdf.org/software/) or the commercial Adobe Acrobat Pro with Preflight 🤑 ## Setting hyperlink colors It's valuable to set the hyperlink colors to *gray* or *black* in order to save money when printing. Tanja found out that it the classic-thesis config package there is a predefined setting for printing. Search for *hypersetup* ```latex \hypersetup{% % uncomment the following line if you want to have black links (e.g., for printing) colorlinks=false, linktocpage=false, pdfstartpage=3, pdfstartview=FitV, pdfborder={0 0 0},% } ``` For *gray* links set ``` \hypersetup{% %... colorlinks=true, allcolors=gray % %... } ``` ## Replace command with words Are you fed up with retyping your thesis topic over and over gain? Just make a command for it <3 ``` \newcommand{\hdf}{\emph{Handoff} and the \emph{Universal Clipboard}} ``` ## Acronyms in plural form Our template uses the glossaries package.The package supports glossary entries, acronyms and symbol defintions. Acronyms are added with `\newacronym{command-form}{replaced-form}{text}` There are two options for plurals: longplural and shortplural ```latex \newacronym[longplural={operating systems}, shortplural={OSes}]{OS}{OS}{operating system} ``` By default plurals are used with `\glspl{}` and it will attach a small *s* to the shortened word. If the short plural or the long plural form is different: use the options. ## Finding marginpars without period Margin notes should be sentences with a period at the end. I tend to forget them and Christian came up with the great idea of making a regex to find them. Here's the regex: ```regex \marginpar\{.*[^.]\} ``` ## Sort lines using TeXstudio To sort lines, e.g., the acromyms, one can add a macro of type *Script* to TeXstudio (Macros >> Edit Macros >> Add) with the following contents: ```javascript %SCRIPT var selected_text = cursor.selectedText() var selected_lines = selected_text.split("\n") selected_lines.sort(function(a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); }) cursor.replaceSelectedText(selected_lines.join("\n")); ``` When run (e.g. through a shortcut), it sorts the selected lines with ignored case. Also see [TeXstudio Wiki](https://sourceforge.net/p/texstudio/wiki/Scripts/) for other macros. ## Clever Referencing To make your life easier with referencing, use the cleveref package which is by default used in the SEEMOO template. ### General Usage With that, you can reference labels with the \cref{} command and it automatically creates the type of reference for you as well. Example: ```latex The \cref{sec:fancy-section} tells you some very fancy shit. \section{Some fancy section} \label{sec:fancy-section} ``` This creates the following: ``` The section XY tells you some very fancy shit. ... ``` Note that you should use \Cref (note the upper case C) for references in the beginning of a sentence. The cleverref package provides some very nice features allowing you to put several references in one command and it sorts out for you how to write it best. For example, you can do something like ```\cref{sec1,sec3,ch2,sec2}``` and it outputs something like ```sections 1 to 3 and chapter 2```. There are also more nice commands if you only need the label or only the number and many more stuff. See the cleverref documentation for this. ### Disable forcing upper-case descriptions By default, the SEEMOO template tells cleveref to make references upper case (like "... Section 2...") independently of the position within the sentence. If that annoys you, go to the *additional-packages.tex* file and strip the option "capitalize" from the ```\PassOptionsToPackage{...}{cleveref}``` call. > Note that upper-case references are the style that is preferred in the SEEMOO thesis guide. ## Table Numbering with integer numbers If `floatperchapter=false` is used, the table numeration starts at 2 for the first table. > I think it's the fact that acronym uses a longtable to display the list of acronomys, which in fact uses automatically a \caption and that increases the table counter, since \printglossaries is right at the start, so the real tables start with a table number of two https://tex.stackexchange.com/questions/270628/problem-with-classicthesis-tables-numeration There are two possible solutions for this: * Add a new glossary style based on longtable* as explained in the accepted answer * Or simply add `\setcounter{table}{0}` directly after `\printglossary` in Contents.tex ## Finding acronyms in your thesis ``` cat *.tex | grep -wo "[A-Z]\+\{2,10\}" | sort | uniq -c | sort -gr ``` Source: http://doofussoftware.blogspot.com/2012/09/a-linux-one-liner-to-find-all-acronyms.html -> See this page for more version, e.g. non-uppercase acronyms ## Ignore underscores in text Sometimes you have to write function, variable, class, etc. names which containes lots of underscores. To prevent LaTeX from interpreting these underscores, just use \detokenize{}. Also useful is defining a command for this class of names: ```tex \newcommand{\programstuff}[1]{\emph{\detokenize{#1}}\xspace} ``` # Other Stuff ## Painless inserting in TeXstutio Normally, inserting stuff in TeXstudio can include some pain when the copied text includes some characters, which represent TeX commands. Fortunately, when using **ctrl+shift+v** to insert text, TeXstudio escapes all these characters resulting in a clean insert.