LoginSignup
7
3

More than 5 years have passed since last update.

LaTeX において大きさを数値で調整できる括弧

Last updated at Posted at 2017-05-05

数式はやはり括弧の大きさを調整することで圧倒的に見やすくなりますが、\bigl / \Bigl / \biggl / \Biggl のような呪文は覚えにくいしわかりにくいです。\left / \right による自動調整もありますが、案外上手く機能しなかったりするので、数値で調整することにしました。

Screenshot 2017-05-05 20.42.44.png

brackets.tex
\documentclass{article}

\usepackage{expl3}
\usepackage{amsmath}
\usepackage{newtxtext}
\usepackage{newtxmath}

\ExplSyntaxOn
\cs_new_eq:NN \If \bool_if:nTF
\cs_new_eq:NN \Compare \int_compare_p:nNn
\ExplSyntaxOff

\newcommand{\leftright}[4][0]{%
    \If{\Compare{#1}={0}}{%
        #2#4#3%
    }{\If{\Compare{#1}={1}}{%
        \bigl#2#4\bigr#3%
    }{\If{\Compare{#1}={2}}{%
        \Bigl#2#4\Bigr#3%
    }{\If{\Compare{#1}={3}}{%
        \biggl#2#4\biggr#3%
    }{\If{\Compare{#1}={4}}{%
        \Biggl#2#4\Biggr#3%
    }{%
        \errmessage{leftright: illegal optional argument}%
    }}}}}%
}

\newcommand{\p}[2][0]{\leftright[#1](){#2}}
\renewcommand{\b}[2][0]{\leftright[#1][]{#2}} % \b used to be a diacritic
\newcommand{\pb}[2][0]{\leftright[#1](]{#2}}
\newcommand{\bp}[2][0]{\leftright[#1][){#2}}
\renewcommand{\c}[2][0]{\leftright[#1]\{\}{#2}} % \c used to be a diacritic
\newcommand{\g}[2][0]{\leftright[#1]\langle\rangle{#2}}
\renewcommand{\t}[2][0]{\leftright[#1]||{#2}} % \t used to be a diacritic
\newcommand{\n}[2][0]{\leftright[#1]\lVert\rVert{#2}}
\newcommand{\f}[2][0]{\leftright[#1]\lfloor\rfloor{#2}}
\renewcommand{\l}[2][0]{\leftright[#1]\lceil\rceil{#2}} % \l used to be a special character

\begin{document}

\[\p[4]{1 + \p[3]{2 + \p[2]{3 + \p[1]{4 + \p{5 + 6} + 7} + 8} + 9} + 10} \times 2 = 10 \times \p{10 + 1} \]
\[\p[4]{\p[3]{\p[2]{\p[1]{\p{}}}}}
\ \b[4]{\b[3]{\b[2]{\b[1]{\b{}}}}}
\ \c[4]{\c[3]{\c[2]{\c[1]{\c{}}}}}
\ \g[4]{\g[3]{\g[2]{\g[1]{\g{}}}}}
\ \t[4]{\t[3]{\t[2]{\t[1]{\t{}}}}}
\ \n[4]{\n[3]{\n[2]{\n[1]{\n{}}}}}
\ \f[4]{\f[3]{\f[2]{\f[1]{\f{}}}}}
\ \l[4]{\l[3]{\l[2]{\l[1]{\l{}}}}}\]

\end{document}

ちょっとした工夫ではありますが、このように括弧をマクロ化しておくと、大きさの調整が圧倒的に楽になるだけでなく、開き括弧と閉じ括弧の対応も自動的に取れるので、非常に便利です。

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3