stb-brackets.sty 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. \NeedsTeXFormat{LaTeX2e}
  2. \ProvidesPackage{stb-brackets}[2019/03/09]
  3. \RequirePackage{etoolbox}
  4. \RequirePackage{mathtools} % Lots of math stuff
  5. \RequirePackage{scalerel} % For scaling bags
  6. \RequirePackage{stmaryrd} % For double brackets and bags
  7. \RequirePackage{xparse}
  8. % --- Delimiter for set-builder notation ---
  9. \newcommand*{\@setbuildermid}{:}
  10. \DeclareOption{setbar}{
  11. \renewcommand*{\@setbuildermid}{\:\delimsize\vert\:}
  12. }
  13. \DeclareOption{setcolon}{
  14. \renewcommand*{\@setbuildermid}{:}
  15. }
  16. % --- Notation for expression evaluation ---
  17. \newcommand*{\@evalleftdelim}{.}
  18. \newcommand*{\@evalbar}{\rvert}
  19. \newcommand*{\@evalrightdelim}{.}
  20. \DeclareOption{evalbar}{
  21. \renewcommand*{\@evalleftdelim}{.}
  22. \renewcommand*{\@evalbar}{\rvert}
  23. \renewcommand*{\@evalrightdelim}{.}
  24. }
  25. \DeclareOption{evalbrackets}{
  26. \renewcommand*{\@evalleftdelim}{\lbrack}
  27. \renewcommand*{\@evalbar}{\rbrack}
  28. \renewcommand*{\@evalrightdelim}{.}
  29. }
  30. \ProcessOptions\relax
  31. % --- Brackets ---
  32. % Helper macro -- adapted from Sebastien Gouezel's code on pg. 29 of the mathtools doumentation
  33. \newcommand{\@MTkillspecial}[1]{
  34. \bgroup
  35. \catcode`\&=9
  36. \let\\\relax%
  37. \scantokens{#1}%
  38. \egroup
  39. }
  40. % Constructor
  41. \NewDocumentCommand{\DeclareSplittableBrackets}{m m m}{%
  42. \DeclarePairedDelimiter{#1}{#2}{#3}
  43. \reDeclarePairedDelimiterInnerWrapper{#1}{star}{
  44. \mathopen{##1\vphantom{\@MTkillspecial{##2}}\kern-\nulldelimiterspace\right.}
  45. ##2
  46. \mathclose{\left.\kern-\nulldelimiterspace\vphantom{\@MTkillspecial{##2}}##3}
  47. }
  48. }
  49. % Common brackets
  50. \AfterEndPreamble{ % Delay this to override unicode-math's override
  51. \undef\angles
  52. \DeclareSplittableBrackets{\angles}{\langle}{\rangle}
  53. }
  54. \DeclareSplittableBrackets{\bars}{\lvert}{\rvert}
  55. \DeclareSplittableBrackets{\braces}{\lbrace}{\rbrace}
  56. \DeclareSplittableBrackets{\brackets}{\lbrack}{\rbrack}
  57. \DeclareSplittableBrackets{\ceil}{\lceil}{\rceil}
  58. \DeclareSplittableBrackets{\dbars}{\lVert}{\rVert}
  59. \DeclareSplittableBrackets{\dbrackets}{\llbracket}{\rrbracket}
  60. \DeclareSplittableBrackets{\floor}{\lfloor}{\rfloor}
  61. \DeclareSplittableBrackets{\parens}{\lparen}{\rparen}
  62. \let\abs\bars
  63. \let\set\braces
  64. % Scalable bags
  65. \NewDocumentCommand{\bags}{s o m}{%
  66. \IfBooleanTF{#1}
  67. {\scaleleftright{\lbag}{#3}{\rbag}}
  68. {{#2 \lbag} #3 {#2 \rbag}}
  69. }
  70. % --- Set-builder notation ---
  71. \DeclarePairedDelimiterX{\setbuilder}[2]{\lbrace}{\rbrace}{#1 \@setbuildermid \mathopen{} #2}
  72. % --- Functions ---
  73. \DeclarePairedDelimiterXPP{\apply}[2]{#1}{\lparen}{\rparen}{}{#2}
  74. \DeclarePairedDelimiterXPP{\applyy}[3]{#1}{\lparen}{\rparen}{}{#2 \delimsize\rparen \delimsize\lparen #3}
  75. \DeclarePairedDelimiterXPP{\applyyy}[4]{#1}{\lparen}{\rparen}{}{#2 \delimsize\rparen \delimsize\lparen #3 \delimsize\rparen \delimsize\lparen #4}
  76. \DeclarePairedDelimiterXPP{\bapply}[2]{#1}{\lbrack}{\rbrack}{}{#2}
  77. \DeclarePairedDelimiterXPP{\restrict}[2]{}{.}{\rvert}{_{#2}}{#1}
  78. \DeclarePairedDelimiterXPP{\evalat}[2]{}{\@evalleftdelim}{\@evalbar}{_{#2}}{#1 \delimsize\@evalrightdelim}
  79. \endinput