Skip to content

Instantly share code, notes, and snippets.

@JeanOlivier
Created April 28, 2020 16:22
Show Gist options
  • Save JeanOlivier/17a595b1ee20f38af5044d463542665d to your computer and use it in GitHub Desktop.
Save JeanOlivier/17a595b1ee20f38af5044d463542665d to your computer and use it in GitHub Desktop.
LaTeX Delimiters with automatic sizing that's easily overridable.
\usepackage{xstring}
% Parenthèses communes via commandes avec taille ajustable en argument optionnel
% La taille par défaut est automatique
%
% Tester ainsi:
% \p{123}
% \p[]{123}
% \p[big]{123}
% \pc[Big]{123}
% \pc[bigg]{123}
% \pa[Bigg]{123}
% \pa[none]{123}
\newcommand{\nicedelim}[4]{%
\IfEqCase{#1}{%
{\left} {\left #2#4 \right #3}%
{\right}{\left #2#4 \right #3}%
{} {\left #2#4 \right #3}%
{big} {\big #2#4 \big #3}%
{Big} {\Big #2#4 \Big #3}%
{bigg} {\bigg #2#4 \bigg #3}%
{Bigg} {\Bigg #2#4 \Bigg #3}%
{none} {#4}%
}[\PackageError{nicedelim}{Undefined parenthesis size "#1", supported size are: big, Big, bigg, Bigg, none for no delimiters, or automatic mode using \left, \right, or [].}{}]%
}
\newcommand{\p}[2][\left]{\nicedelim{#1}{(}{)}{#2}} % p => Parenthèse
\newcommand{\pc}[2][\left]{\nicedelim{#1}{[}{]}{#2}} % pc => Parenthèse Carrée
\newcommand{\pa}[2][\left]{\nicedelim{#1}{\{}{\}}{#2}} % pa => Parenthèse Accollade
\newcommand{\norm}[2][\left]{\nicedelim{#1}{|}{|}{#2}} % norme
\newcommand{\mean}[2][\left]{\nicedelim{#1}{\langle}{\rangle}{#2}} % Mean => Moyenne
% Convenient
\newcommand{\abs}{\norm} % Valeur Absolue
\newcommand{\moy}{\mean} % Moyenne en Français
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment