Files
phd-thesis/config/thesis_commands.tex
2024-08-02 18:21:11 +02:00

84 lines
2.5 KiB
TeX

\newcommand{\importchapter}[2]{% Load a chapter (#2) in a path (#1)
\cleardoublepage% after a clear double page
\graphicspath{{#1/figures/}}% with figures
\includefrom{#1}{#2}% and relative paths \input in the chapter
}
\newcommand{\chaptertoc}{% Print the table of contents for the chapter
\vspace*{-1cm}%
\horizontalrule%
\vspace*{-0.5cm}%
\localtableofcontents%
\horizontalrule%
}
% Add chapter label as prefix to all other sub-labels
\NewCommandCopy{\oldlabel}{\label}
\newcommand{\labelprefix}{main}
\newcommand{\mainlabel}[1]{%
\renewcommand{\labelprefix}{#1}%
\oldlabel{\labelprefix}%
}
\renewcommand{\label}[1]{\oldlabel{\labelprefix:#1}}
% References
\newcommand{\chapref}[1]{Chapter~\ref{#1}}
\renewcommand{\eqref}[2][\labelprefix]{Equation~\ref{#1:eq:#2}}
\renewcommand{\figref}[2][\labelprefix]{Figure~\ref{#1:fig:#2}}
\newcommand{\partref}[1]{Part~\ref{#1}}
\renewcommand{\secref}[2][\labelprefix]{Section~\ref{#1:sec:#2}}
\renewcommand{\tabref}[2][\labelprefix]{Table~\ref{#1:tab:#2}}
% Images
% example: \fig[1]{universe}{The Universe}[Additional caption text, not shown in the list of figures]
% reference later with: \figref{universe}
\RenewDocumentCommand{\fig}{O{1} O{htbp} m m o}{%
\begin{figure}[#2]
\centering%
\includegraphics[width=#1\linewidth]{#3}%
\caption[#4]{#4\IfValueTF{#5}{ #5}}% voluntary space before the subfig titles
\label{fig:#3}%
\end{figure}%
}
% example:
% \begin{subfigs}{label}{Fig title}[Subfig titles]
% \subfig{subfig1}%
% \subfig[1][htbp]{subfig2}[caption]%
% \end{subfigs}
% reference later with: \figref{label}
\RenewDocumentEnvironment{subfigs}{O{htbp} m m o}{%
\begin{figure}[#1]%
\centering%
}{%
\caption[#3]{%
#3%
\IfValueTF{#4}{ % voluntary space before the subfig titles
\begin{enumerate*}[label=\textbf{(\alph*)}]%
#4%
\end{enumerate*}%
}%
}%
\label{fig:#2}%
\end{figure}%
}
\NewDocumentCommand{\subfigsheight}{m}{%
\setkeys{Gin}{height=#1}%
}
\RenewDocumentCommand{\subfig}{o O{b} m O{}}{%
\hfill%
\subfloat[#4\label{fig:#3}]{%
\IfValueTF{#1}{%
\includegraphics[width=#1\linewidth, valign=#2, keepaspectratio]{#3}%
}{%
\includegraphics[valign=#2, keepaspectratio]{#3}%
}%
}%
\hfill%
}
\captionsetup{%
labelfont={sf,bf,up}, % sans-serif, bold, upright
}