| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2022-2023 by Antoine Missier <[email protected]> |
| 4 |
% |
| 5 |
% This file may be distributed and/or modified under the conditions of |
| 6 |
% the LaTeX Project Public License, either version 1.3 of this license |
| 7 |
% or (at your option) any later version. The latest version of this |
| 8 |
% license is in: |
| 9 |
% |
| 10 |
% http://www.latex-project.org/lppl.txt |
| 11 |
% |
| 12 |
% and version 1.3 or later is part of all distributions of LaTeX version |
| 13 |
% 2005/12/01 or later. |
| 14 |
% \fi |
| 15 |
% |
| 16 |
% \iffalse |
| 17 |
%<*driver> |
| 18 |
\ProvidesFile{ibrackets.dtx} |
| 19 |
%</driver> |
| 20 |
%<*package> |
| 21 |
\NeedsTeXFormat{LaTeX2e}[2005/12/01] |
| 22 |
\ProvidesPackage{ibrackets} |
| 23 |
[2023/07/26 v1.2 .dtx ibrackets file] |
| 24 |
%</package> |
| 25 |
%<*driver> |
| 26 |
\documentclass{ltxdoc} |
| 27 |
\usepackage[utf8]{inputenc} |
| 28 |
\usepackage[T1]{fontenc} |
| 29 |
\usepackage[english]{babel} |
| 30 |
\usepackage[charter]{mathdesign} |
| 31 |
\usepackage{amsmath} |
| 32 |
\usepackage{ibrackets} |
| 33 |
\usepackage{sectsty} |
| 34 |
\usepackage{xcolor} |
| 35 |
|
| 36 |
\definecolor{darkbrown}{rgb}{0.5,0.1,0.1} |
| 37 |
\allsectionsfont{\color{darkbrown}} |
| 38 |
\renewcommand\pi{\piup} |
| 39 |
|
| 40 |
\DisableCrossrefs |
| 41 |
%\CodelineIndex |
| 42 |
%\RecordChanges |
| 43 |
\usepackage{hyperref} |
| 44 |
\hypersetup{% |
| 45 |
colorlinks, |
| 46 |
linkcolor=blue, |
| 47 |
citecolor=red, |
| 48 |
pdftitle={ibrackets}, |
| 49 |
pdfsubject={LaTeX package}, |
| 50 |
pdfauthor={Antoine Missier} |
| 51 |
} |
| 52 |
\MakeShortVerb{"} |
| 53 |
\begin{document} |
| 54 |
\DocInput{ibrackets.dtx} |
| 55 |
%\PrintChanges |
| 56 |
%\PrintIndex |
| 57 |
\end{document} |
| 58 |
%</driver> |
| 59 |
% \fi |
| 60 |
% |
| 61 |
% \CheckSum{49} |
| 62 |
% |
| 63 |
% \CharacterTable |
| 64 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 65 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 66 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 67 |
% Exclamation \! Double quote \" Hash (number) \# |
| 68 |
% Dollar \$ Percent \% Ampersand \& |
| 69 |
% Acute accent \' Left paren \( Right paren \) |
| 70 |
% Asterisk \* Plus \+ Comma \, |
| 71 |
% Minus \- Point \. Solidus \/ |
| 72 |
% Colon \: Semicolon \; Less than \< |
| 73 |
% Equals \= Greater than \> Question mark \? |
| 74 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 75 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 76 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 77 |
% Right brace \} Tilde \~} |
| 78 |
% |
| 79 |
% \changes{v1.0}{2022/12/19}{Initial version} |
| 80 |
% |
| 81 |
% \changes{v1.1}{2022/12/28}{ |
| 82 |
% - A bug correction in the README.md file |
| 83 |
% - Tiny changes in documentation} |
| 84 |
% |
| 85 |
% \changes{v1.2}{2023/07/26}{Minor changes in the documentation} |
| 86 |
% |
| 87 |
% \GetFileInfo{ibrackets.sty} |
| 88 |
% |
| 89 |
% \title{Intelligent brackets \\ The \textsf{ibrackets} package} |
| 90 |
% \author{Antoine Missier \\ \texttt{[email protected]}} |
| 91 |
% \date{\filedate, \fileversion} |
| 92 |
% \maketitle |
| 93 |
% |
| 94 |
% \section{Introduction} |
| 95 |
% |
| 96 |
% Open intervals are commonly represented with parenthesis, e.g.\@ $(0, +\infty)$ |
| 97 |
% but sometimes square brackets are used, especially in French mathematics: $]0, +\infty[$. |
| 98 |
% In that specific case, the space around the square brackets is often inappropriate, |
| 99 |
% as in the expression $x \in \mathclose{]} 0, +\infty\mathopen{[}$. |
| 100 |
% This small package address this issue and |
| 101 |
% redefines brackets symbols $[$ and $]$ for mathematical mode |
| 102 |
% to get correct spacing: $x \in ]0, +\infty[$. |
| 103 |
% |
| 104 |
% \medskip |
| 105 |
% Originally implemented in the \textsf{mismath} package~\cite{MIS} |
| 106 |
% and also in \textsf{frenchmath}~\cite{FR} |
| 107 |
% since version 2.1, our previous redefinitions produce however incorrect spacing |
| 108 |
% when the left bound of the interval begins with a sign - or +, |
| 109 |
% which was then interpreted as a binary operation. As a result, blank |
| 110 |
% spaces surrounding the sign would have been too large. |
| 111 |
% This issue was pointed out by Jean-François Burnol, and |
| 112 |
% an easy solution, that has been documented, consists of nesting the operator |
| 113 |
% or the left bound within a pair of braces, |
| 114 |
% e.g.\@ |$x \in ]{-}\infty, 0]$|, or using |\left| and |\right| |
| 115 |
% or even |\mathopen{]}|. |
| 116 |
% |
| 117 |
% \medskip |
| 118 |
% Inspired by Walter Schmidt's \textsf{icomma} package~\cite{ICOMMA}, we now provide |
| 119 |
% an improved bracket definition that works correctly without the need for |
| 120 |
% these pairs of braces. |
| 121 |
% |
| 122 |
% \medskip |
| 123 |
% Let's also mention other approaches, such as the |\DeclarePairedDelimiters| macro from |
| 124 |
% the \textsf{mathtools} package~\cite{TOOL}, or |
| 125 |
% the \textsf{interval} package~\cite{INT} with its |
| 126 |
% |\interval| macro. However our solution is more lightweight. |
| 127 |
% |
| 128 |
% \section{Usage} |
| 129 |
% With the \textsf{ibrackets} package, you can easily type intervals. For example the code |
| 130 |
% |$x\in]0,\pi[\cup]2\pi, 3\pi[$| yields |
| 131 |
% \begin{align*} |
| 132 |
% x\in]0, \pi[\cup]2\pi, 3\pi[ &\mbox{\quad with \textsf{ibrackets}}, \\ |
| 133 |
% \text{instead of \quad} |
| 134 |
% x\in\mathclose{]} 0,\pi \mathopen{[}\cup\mathclose{]} 2\pi, 3\pi\mathopen{[} |
| 135 |
% &\mbox{\quad without \textsf{ibrackets}}. |
| 136 |
% \end{align*} |
| 137 |
% |
| 138 |
% For the example in the introduction the spacing is now correct with the following simple code: |
| 139 |
% |$x \in ]-\infty, 0]$|, which gives $x \in ]-\infty, 0]$. |
| 140 |
% |
| 141 |
% \medskip |
| 142 |
% In \textsf{ibrackets}, the symbols $[$ and $]$ |
| 143 |
% and are not defined by default as delimiters. |
| 144 |
% Therefore, a line break could occur between the two brackets. However, |
| 145 |
% it is always possible to transform them |
| 146 |
% into delimiters using |\left| and |\right|. |
| 147 |
% |
| 148 |
% \medskip |
| 149 |
% Actually, brackets are set as ``active'' characters, |
| 150 |
% behaving like ordinary characters in most cases. |
| 151 |
% However, when a bracket is \emph{immediately} followed by a + or - character, |
| 152 |
% it becomes an open delimiter. Therefore, when the left bound contains an operator sign, |
| 153 |
% \emph{you don't have to leave a space between the first bracket and the sign}, |
| 154 |
% otherwise, the spaces surrounding the operator will be too large. |
| 155 |
% For example if you write |$x \in ] -\infty, 0]$| it yields $x \in ] -\infty, 0]$ |
| 156 |
% instead of $x \in ]-\infty, 0]$. |
| 157 |
% Conversely, when dealing with algebraic expressions involving intervals, |
| 158 |
% \emph{you must leave a space between the second bracket and the} +/- \emph{operations} |
| 159 |
% to maintain proper spacing. |
| 160 |
% For instance |$[a, b] + [c, d]$| yields $[a, b] + [c, d]$ |
| 161 |
% while |$[a, b]+ [c, d]$| would yield $[a, b]+ [c, d]$. |
| 162 |
% |
| 163 |
% \StopEventually{} |
| 164 |
% |
| 165 |
% \section{Implementation} |
| 166 |
% At |\begin{document}|, we store the original "\mathcode" of the brackets, |
| 167 |
% in the |\math...bracket| macros, and then we make the brackets active in math mode. |
| 168 |
% \begin{macrocode} |
| 169 |
\AtBeginDocument{% |
| 170 |
\mathchardef\mathopenbracket\mathcode`[% |
| 171 |
\mathcode`[="8000 |
| 172 |
\mathchardef\mathclosebracket\mathcode`]% |
| 173 |
\mathcode`]="8000 |
| 174 |
} |
| 175 |
|
| 176 |
% \end{macrocode} |
| 177 |
% The active brackets check the next input character. If the next character is a - or a +, |
| 178 |
% the active brackets return |\mathopen| with the saved |\math...bracket|, |
| 179 |
% so that no space will be added after the bracket. |
| 180 |
% Otherwise, |\mathord\math...bracket| is returned. |
| 181 |
% \begin{macrocode} |
| 182 |
{\catcode`[=\active |
| 183 |
\gdef[{\futurelet\@next\sm@rtopenbracket}} |
| 184 |
\def\sm@rtopenbracket{% |
| 185 |
\ifx\@next- \mathopen \else |
| 186 |
\ifx\@next+ \mathopen \else |
| 187 |
\mathord\fi\fi \mathopenbracket} |
| 188 |
|
| 189 |
{\catcode`]=\active |
| 190 |
\gdef]{\futurelet\@next\sm@rtclosebracket}} |
| 191 |
\def\sm@rtclosebracket{% |
| 192 |
\ifx\@next- \mathopen \else |
| 193 |
\ifx\@next+ \mathopen \else |
| 194 |
\mathord\fi\fi \mathclosebracket} |
| 195 |
% \end{macrocode} |
| 196 |
% We could have use the internal \TeX\ command |\@ifnextchar| |
| 197 |
% to skip blank spaces after the bracket and look if there is a + or - after, |
| 198 |
% but then it would become tricky when you really want |
| 199 |
% to follow an interval with an operation plus or minus. |
| 200 |
% |
| 201 |
% \begin{thebibliography}{5} |
| 202 |
% % \begin{raggedright} |
| 203 |
% \bibitem{MIS} \emph{\textsf{mismath} -- Miscellaneous mathematical macros}. |
| 204 |
% Antoine Missier, CTAN, v2.0 2022/11/11. |
| 205 |
% \bibitem{FR} \emph{L'extension \textsf{frenchmath}}. Antoine Missier, CTAN, v2.2 2022/12/15. |
| 206 |
% \bibitem{ICOMMA} \emph{The \textsf{icomma} package for \LaTeXe}. |
| 207 |
% Walter Schmidt, CTAN, v2.0 2002/03/10. |
| 208 |
% \bibitem{TOOL} \emph{The \textsf{mathtools} package}. Morten Høgholm, Lars Madsen, CTAN, |
| 209 |
% v1.21 2018/01/08. |
| 210 |
% \bibitem{INT} \emph{The \textsf{interval} package}. Lars Madsen, CTAN, |
| 211 |
% v0.4 2019/03/06. |
| 212 |
% \end{raggedright} |
| 213 |
% \end{thebibliography} |
| 214 |
% \Finale |
| 215 |
\endinput |