%may need to define type of input for \newcommands if autocompletion is desired.
%See https://htmlpreview.github.io/?https://github.com/texstudio-org/texstudio/master/utilities/manual/usermanual_en.html#classification-format for documentation.
%See https://github.com/texstudio-org/texstudio/wiki/Frequently-Asked-Questions#why-does-a-command-not-show-up-in-the-completion for further explanations
%texstudio paths:
%/autohome/saeckech/.config/texstudio/completion/ (office computer)

%global booleans
\newif\ifshownotes%created a variable "shownotes" which I could set to be true or false, which was then used to show or hide a sections of text
\shownotesfalse% sets the value of this variable to false. change the ending from "false" to "true" to set it to true. I.e.: \shownotesfalse or \shownotestrue
%https://tex.stackexchange.com/questions/61933/best-practice-for-getting-if-not-foo-conditionals

%global plot parameters
\newcommand{\wrapfigscaling}{0.9\linewidth}%used as the default value for how much of the linewidth a figure with wrapped-around text should occupy. (Ended up not using wrapped text after all)
\def\defaultfigurewidth{0.95\linewidth}%used as the default value for how much of the linewidth a figure with a single panel should occupy
\def\defaulttwosubfigwidth{0.49\linewidth}%used as the default value for how much of the linewidth a figure with two panels should occupy
%
%mosaic plots were not used after all in my final dissertation version.
%\def\mosaiccolumnbig{0.575\linewidth}%used as the default value for how much space a big panel in a mosaic plot should occupy. I only used two sizes of panels in mosaic plots
%\def\mosaiccolumnsmall{0.375\linewidth}%used as the default value for how much space a small panel in a mosaic plot should occupy. I only used two sizes of panels in mosaic plots
\def\defaultfigureSmallHeight{5cm}%another default value, e.g. for a series of photos of the sample over time. Did not need to be as large as figures with data in my case
\captionsetup{format=plain, labelfont+=bf}%handles formatting of figure captions. https://latex-tutorial.com/caption-customization-latex/

%citations
%This commands overrides the biblatex maxcitenames package option% https://tex.stackexchange.com/questions/454868/biblatex-change-maximum-number-of-authors-locally
\makeatletter
\newrobustcmd*{\setmaxcitenames}{\numdef\blx@maxcitenames}
\makeatother
\def\globalmaxnames{2}%store number of names before abbreviating to "author et al". in a variable, so that it can be changed and reset in special cases (i.e. the group of Winnik et al. intensively studied cononsolvency with methanol)
%example: %\setmaxcitenames{1}\textcite{Winnik1990}\setmaxcitenames{\globalmaxnames}
%solution for new textcite command with only one author for different citation style: https://tex.stackexchange.com/questions/137104/new-command-like-textcite-but-with-only-one-author

%glossary shorthands: often-used glossary terms for which I did not want to type the glossary command every time.
%the \xspace command determines whether a space should be added (more words follow) or not (interpuncation follows). Package says that one should manually check whether it worked appropriately, but I did not have much trouble with it. Can be combined with the \unskip command to handle special cases
\newcommand{\AEON}{\SI{1}{\giga\hertz}-AEON spectrometer\xspace}
\newcommand{\CPMG}{\gls{CPMG}\xspace}
\newcommand{\LCST}{\gls{LCST}\xspace}
\newcommand{\pNIPAM}{\gls{pNIPAM}\xspace}
%\newcommand{\pNIPAMadj}[1]{\mbox{\pNIPAM-}\allowbreak#1\unskip\xspace}%adjectives such as ``pNIPAM-based''
\newcommand{\pNIPAMbinary}[1]{\mbox{\pNIPAM/}\allowbreak#1\unskip\xspace}%pNIPAM in binary mixtures such as ``pNIPAM/water''
\newcommand{\pNIPAMternary}[2]{\mbox{\pNIPAM/}\allowbreak \mbox{#1\unskip/}\allowbreak #2\unskip\xspace}%pNIPAM in ternary mixtures such as ``pNIPAM/ethanol/water''
%above few commands in their german version: (not used often but defined as commands to remember adjusting german versions as well if changes are made to english versions)
%in case you regularly need secondary-language acronym adaptions, see https://tex.stackexchange.com/questions/136634/glossaries-acronyms-two-languages or https://tex.stackexchange.com/questions/128334/using-bi-lingual-entries-with-the-glossaries-package
%otherwise, you can simply create new entries. Mind that they may appear in the glossary
%\newcommand{\PNIPAMadj}[1]{\mbox{\gls{pNIPAMgerman}-}\allowbreak#1\unskip\xspace}

%commands for future typesetting. I used a bunch of those, but only keep a few examples here.
%note: starred version of \newcommand have additional error checking and are apparently considered better practice, unless weird arguments require the non-starred version. I wont adhere to this however, because I dont care.
\newcommand{\AxisTypeface}[1]{\ensuremath{\mathrm{#1}}\xspace}%defer final decision on whether e.g. x in x-axis is a variable (italic) or descriptive (roman)
\newcommand*\chem[1]{\ensuremath{\mathrm{#1}}}%math mode to allow subscripts as in $H_2O$. Could also have used \textsubscript instead. Use a macro to penaltize hyphenation and easily unify (and possibly change) typesetting. Big packages like mchem or chemformula are a bit overkill for me.
\newcommand{\eqend}[1]{\text{\quad#1}}%argrument is for interpunctation in math environment after an equation.
\newcommand{\eqpl}[1]{eqs.~\eqref{#1}}%reference a parent equation. pluralequation crefformat (https://tex.stackexchange.com/questions/35772/referencing-subequations-with-cleveref) did not work.
\newcommand{\Eqpl}[1]{Equations~\eqref{#1}}
\newcommand{\HamOpQP}{\ensuremath{\hat{H}_\mathrm{Q}}}%Hamilton operator for quadrupolar interaction
\newcommand{\wL}{\ensuremath{\omega_\mathrm{L}}\xspace}%Larmor frequency
\newcommand{\RankOrderTypeface}[1]{\ensuremath{\mathrm{#1}}\xspace}%defer final decision on whether e.g. rank of a spherical harmonic is a variable (italic) or descriptive (roman)
\newcommand{\Rh}{\ensuremath{R_\mathrm{h}}}%hydrodynamic radius
\newcommand{\QCC}{\ensuremath{C_\mathrm{Q}}\xspace}%{\textit{QCC}\xspace}%quadrupole coupling constant
\newcommand{\deltaQ}{\ensuremath{\delta_\mathrm{Q}}\xspace}%quadrupole anisotropy
\newcommand{\etaQ}{\ensuremath{\eta_\mathrm{Q}}\xspace}%quadrupole asymmetry
\newcommand{\QMoment}{\ensuremath{\mathcal{Q}\xspace}}%(electrical) quadrupole moment (of a nucleus)
\newcommand{\tRhoChange}{\ensuremath{t}}%symbol for time-argument for $\derivative{\rho_\mathrm{R}(t)}{t}$. May conflict with the use of an subscript-free $\tau$ as the characteristic decay time of the orientational correlations or the time-argument of the correlation function
\newcommand{\tCorrfuncArg}{\ensuremath{\mathcal{T}}}%{\ensuremath{\tau}}%symbol for time-argument of the autocorrelation function f(t). May conflict with the use of an subscript-free $\tau$ as the characteristic decay time of the orientational correlations or the time-argument of the change in the density matrix
\newcommand{\TOne}[1][]{\ensuremath{{T_1^\textrm{#1}}}\xspace}%spin-lattice relaxation time T1
\newcommand{\TTwo}[1][]{\ensuremath{{T_2^\textrm{#1}}}\xspace}%spin-spin relaxation time T2
\newcommand{\DTwoO}{\chem{D_2O}\xspace}
%\newcommand{\HDO}{\chem{HDO}\xspace}
\newcommand{\HTwoSvntnO}{\chem{H_2}\chem{^{17}O}\xspace}
\newcommand{\HTwoSvntnOHighlight}{\chem{H_2}\chem{\textcolor{red}{^{17}O}}\xspace}
\newcommand{\EtOHDTwoChem}{\chem{CH_3C{^2H}_2OH}\xspace}
\newcommand{\EtOHDTwoChemHighlight}{\chem{CH_3C\textcolor{red}{^2H}_2OH}\xspace}

%sample abbreviations
%naming of samples with linear pNIPAM
\newcommand{\pLinSample}[2][O]{\mbox{%mbox to prevent linebreaks in sample name
	\ifthenelse{\cnttest{#2}{=}{100}}%if (outer)
	{\textrm{Lin-E#2\xspace}}%then (outer)
	{\ifthenelse{\cnttest{#2}{=}{0}}%if (inner)
		{\textrm{Lin-W\ensuremath{_\text{#1}}\SUBTRACT{100}{#2}{\wfrac}\wfrac}\xspace}%then (inner)
		{\textrm{Lin-E#2W\ensuremath{_\text{#1}}\SUBTRACT{100}{#2}{\wfrac}\wfrac}\xspace}%else (inner)
	}%else (outer)
}%close mbox
}%linear pNIPAM samples. Arg1=EtOH Concentration, Arg2=special suffixes (e.g. \pLinSample[0][-D$_2$O]}). Syntax: \newcommand{\commandname}[total number of arguments][default value of optional arguments, which are numbered from 1 to the total number of arguments]{code}
%naming of samples without pNIPAM
\newcommand{\BulkSample}[2][O]{\mbox{%mbox to prevent linebreaks in sample name
	\ifthenelse{\cnttest{#2}{=}{100}}%if (outer)
	{\textrm{F-E#2\xspace}}%then (outer)
	{\ifthenelse{\cnttest{#2}{=}{0}}%if (inner)
		{\textrm{F-W\ensuremath{_\text{#1}}\SUBTRACT{100}{#2}{\wfrac}\wfrac}\xspace}%then (inner)
		{\textrm{F-E#2W\ensuremath{_\text{#1}}\SUBTRACT{100}{#2}{\wfrac}\wfrac}\xspace}%else (inner)
	}%else (outer)
}%close mbox
}
%only one microgel sample made it into the final version of the dissertation, no need for a complex command
\newcommand{\pMGSample}{\mbox{MG-W\ensuremath{_\text{D}}100}\xspace}%mbox to prevent linebreaks in sample name
\newcommand{\BayreuthSample}[2][O]{\mbox{%mbox to prevent linebreaks in sample name
		\ifthenelse{\cnttest{#2}{=}{100}}%if (outer)
		{\textrm{Lin*-E#2\xspace}}%then (outer)
		{\ifthenelse{\cnttest{#2}{=}{0}}%if (inner)
			{\textrm{Lin*-W\ensuremath{_\text{#1}}\SUBTRACT{100}{#2}{\wfrac}\wfrac}\xspace}%then (inner)
			{\textrm{Lin*-E#2W\ensuremath{_\text{#1}}\SUBTRACT{100}{#2}{\wfrac}\wfrac}\xspace}%else (inner)
		}%else (outer)
	}%close mbox
}

%write equations which are repeated (appendix and main part) as macro to ensure consistency
%https://tex.stackexchange.com/questions/254173/how-to-use-macros-to-repeat-math-equations-in-different-settings
%https://tex.stackexchange.com/questions/67651/repeating-an-equation-and-getting-the-same-equation-number
\newcommand{\correlationfunctiondef}[1]{#1f_{2,\RankOrderTypeface{m}}(\tCorrfuncArg) \equiv (-1)^m \overline{R_2^\RankOrderTypeface{-m}(t) R_2^\RankOrderTypeface{m}(\tRhoChange-\tCorrfuncArg)}}%optional command argument for potential alignment characters
\newcommand{\spectraldensitydefRHS}{\int_{0}^{\infty} f_{2,\RankOrderTypeface{m}}(\tCorrfuncArg) \exp(i m \omega) \diff \tCorrfuncArg}

%shorthands for special terms listed in the ignored glossary. %starred version of \gls does not create an internal link
\newcommand{\CD}{\gls*{Cole-Davidson}\xspace}
\newcommand{\fmX}[1][]{fast-motion #1\xspace}%as command in case I change my mind on hyphenation
\newcommand{\HE}{\gls*{HE}\xspace}
\newcommand{\SE}{\gls*{SE}\xspace}
\newcommand{\Tdem}{\gls*{Tdem}\xspace}

%physical constants shorthands
\newcommand{\kB}{\ensuremath{\mathrm{k}_\mathrm{B}}\xspace}% typesetting of the Boltzman constant
%\newcommand{\NA}{\ensuremath{N_\mathrm{A}}\xspace}% typesetting of the Avogadro number
%\newcommand{\Rgas}{\mathrm{R}}% typesetting of the universal gas constant

%additional units with the typesetting of \SI{}{}
\DeclareSIUnit{\wtpercent}{wt\%}
\DeclareSIUnit{\volpercent}{vol\%}
\DeclareSIUnit{\molpercent}{mol\%}
\DeclareSIUnit{\atpercent}{at\%}
\DeclareSIUnit{\barpress}{bar}%bar as a unit of pressure. keep distinct from overbar command
\DeclareSIUnit{\pH}{pH}
\DeclareSIUnit{\ppm}{ppm}%parts per million (chemical shifts)
\DeclareSIUnit{\poise}{P}
\DeclareSIUnit{\hour}{h}
\DeclareSIUnit{\day}{d}
\DeclareSIUnit{\rpm}{rpm}%rounds per minute (e.g. stirring during microgel synthesis)

%customizable row and column vectors. Taken from https://tex.stackexchange.com/questions/39051/typesetting-a-row-vector as of 2024-10-22
\ExplSyntaxOn
\NewDocumentCommand{\Rowvec}{ O{,} m }
{
	\vector_main:nnnn { p } { & } { #1 } { #2 }
}
\NewDocumentCommand{\Colvec}{ O{,} m }
{
	\vector_main:nnnn { p } { \\ } { #1 } { #2 }
}

\seq_new:N \l__vector_arg_seq
\cs_new_protected:Npn \vector_main:nnnn #1 #2 #3 #4
{
	\seq_set_split:Nnn \l__vector_arg_seq { #3 } { #4 }
	\begin{#1matrix}
		\seq_use:Nnnn \l__vector_arg_seq { #2 } { #2 } { #2 }
	\end{#1matrix}
}
\ExplSyntaxOff
\newcommand{\Transpose}{\ensuremath{^\mathrm{T}}\xspace}

%front- and backmatter sections
%https://tex.stackexchange.com/questions/197303/sections-in-toc-with-links-but-without-headings
%\newcommand*\silentsection[1]{%
%	\addtocounter{section}{1}
%	\addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}
%	\sectionmark{#1} % this is to get headers for the section
%}
%\newcommand*\silentchapter[1]{%
%\addtocounter{chapter}{1}
%\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}
%\sectionmark{#1} % this is to get headers for the section
%}
%alternative: https://tex.stackexchange.com/questions/129978/how-to-remove-section-subsection-titles