Skip to content

Instantly share code, notes, and snippets.

@DominikPeters
Last active May 1, 2024 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominikPeters/dc0cce4ea83c42f2ed6da95291193c83 to your computer and use it in GitHub Desktop.
Save DominikPeters/dc0cce4ea83c42f2ed6da95291193c83 to your computer and use it in GitHub Desktop.
LaTeX snippets that I often use in papers

Website version style

\documentclass[11pt]{scrartcl}
\usepackage[a4paper, total={16cm, 24cm}]{geometry}
\usepackage{authblk}
\renewcommand\Authfont{\Large\sffamily}
\renewcommand\Affilfont{\large}
\author[1]{Author 1}
\author[2]{Author 2}
\author[3]{Dominik Peters}
% or with line break: \author[1,2]{\authorcr Dominik Peters}
\affil[1]{Affiliation} 
\affil[2]{Affiliation} 
\affil[3]{CNRS, LAMSADE, Universit\'e Paris Dauphine - PSL}

% KOMA-script: change caption style
\setcapindent{0pt}
\setkomafont{captionlabel}{\sffamily\bfseries}
\renewcommand*{\captionformat}{\hspace{0.5em}}

Make the bibliography appear as a section in table of contents

\renewcommand{\bibsection}{\section{\bibname}} % make bib appear in toc
% or when using KOMA-script
\KOMAoptions{toc=bibnumbered}

Hyperref configuration including back references from the bibliography to the pages where the reference was cited.

\usepackage[pagebackref]{hyperref}
\hypersetup{
	pdfencoding=auto, 
	psdextra,
	colorlinks=true,
	citecolor=green!50!black,
	linkcolor=red!60!black,
	urlcolor=blue!90!black
}
\renewcommand*{\backref}[1]{[$\to$ p. #1]}

Cleveref configuration including code that makes Crefs in section titles show up correctly in the PDF table of contents.

\usepackage[nameinlink]{cleveref}
% handle Cref in section titles
\usepackage{crossreftools}
\pdfstringdefDisableCommands{%
	\let\Cref\crtCref
	\let\cref\crtcref
}
% Make cleveref write 1(a) instead of 1a
\usepackage{subcaption}
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
\renewcommand\thesubfigure{(\alph{subfigure})}

Use better versions of common symbols.

\renewcommand*{\le}{\leqslant}
\renewcommand*{\leq}{\leqslant}
\renewcommand*{\ge}{\geqslant}
\renewcommand*{\geq}{\geqslant}
\renewcommand{\epsilon}{\varepsilon}
\newcommand{\pref}{\succcurlyeq}

Todos

\usepackage[backgroundcolor=orange!15!white,bordercolor=orange!80!black,textsize=small]{todonotes}
\tikzset{/tikz/notestyleraw/.append style={rounded corners=0pt,inner sep=0.6ex}}
\presetkeys{todonotes}{inline}{}

Patching spacing of wrapfigure

\usepackage{wrapfig}
\usepackage{etoolbox}
\makeatletter
\patchcmd\WF@putfigmaybe{\lower\intextsep}{}{}{\fail}%
\AddToHook{env/wrapfigure/begin}{\setlength{\intextsep}{0pt}}
\makeatother

Standard theorem environments

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{claim}[theorem]{Claim}
\newtheorem{example}[theorem]{Example}
\newtheorem{observation}[theorem]{Observation}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{remark}[theorem]{Remark}
% when relevant: \Crefname{algocf}{Algorithm}{Algorithms}

TikZ checkmark and cross

\newcommand{\xmark}{%
\tikz[scale=0.23,draw=black!50!red] {
    \draw[line width=0.7,line cap=round] (0,0) to [bend left=6] (1,1);
    \draw[line width=0.7,line cap=round] (0.2,0.95) to [bend right=3] (0.8,0.05);
}}
\newcommand{\cmark}{%
\tikz[scale=0.23,draw=green!50!black] {
    \draw[line width=0.7,line cap=round] (0.25,0) to [bend left=10] (1,1);
    \draw[line width=0.8,line cap=round] (0,0.35) to [bend right=1] (0.23,0);
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment