# Modify braket package for different brackets forms

I really don't know how to properly modify codes. Still, my problem is that I would like to know how to modify the following code from the package braket (in the link the whole .sty file, which is quite small btw, the code below is more than half of the entire code) to get it work for all sort of brackets.

Here there is the piece of code from the link I think is relevant here:

% \Set{...|...} Only the first | is treated specially.
{\catcode\|=\active
\xdef\set{\protect\expandafter\noexpand\csname set \endcsname}
\expandafter\gdef\csname set \endcsname#1{\mathinner
{\lbrace\,{\mathcode\|32768\let|\midvert #1}\,\rbrace}}
\xdef\Set{\protect\expandafter\noexpand\csname Set \endcsname}
\expandafter\gdef\csname Set \endcsname#1{\left\{%
\ifx\SavedDoubleVert\relax \let\SavedDoubleVert\|\fi
\:{\let\|\SetDoubleVert
\mathcode\|32768\let|\SetVert
#1}\:\right\}}
}
\def\midvert{\egroup\mid\bgroup}
\def\SetVert{\@ifnextchar|{\|\@gobble}% turn || into \|
{\egroup\;\mid@vertical\;\bgroup}}
\def\SetDoubleVert{\egroup\;\mid@dblvertical\;\bgroup}

% If the user is using e-TeX with its \middle primitive, use that for
%
\begingroup
\edef\@tempa{\meaning\middle}
\edef\@tempb{\string\middle}
\expandafter \endgroup \ifx\@tempa\@tempb
\def\mid@vertical{\middle|}
\def\mid@dblvertical{\middle\SavedDoubleVert}
\else
\def\mid@vertical{\mskip1mu\vrule\mskip1mu}
\def\mid@dblvertical{\mskip1mu\vrule\mskip2.5mu\vrule\mskip1mu}
\fi


Thus, I would like to know how to modify the code to create new commands (e.g. a command \Name) such that I get – say – square brackets, and the delimiter | still adapts in the middle to the size of the brackets.

How to do it?

Any feedback is most welcome!

PS: Actually, the idea of the original developer was exactly to give the flexibility to all users to modify braket in their own way... however I am clearly a not sophisticated enough user. :)

I don't know much about the braket package, but the mathtools package provides some nice commands for declaring paired delimiters. In particular, the documentation gives some examples of defining braket-like macros using \DeclarePairedDelimiterX.

For example, the documentation gives the following code snippet for what I think you might want (a braket-like set macro):

% just to make sure it exists
\providecommand\given{}
% can be useful to refer to this outside \Set
\newcommand\SetSymbol[1][]{%
\nonscript\:#1\vert
\allowbreak
\nonscript\:
\mathopen{}}
\DeclarePairedDelimiterX\Set[1]\{\}{%
\renewcommand\given{\SetSymbol[\delimsize]}
#1
}

$\Set*{ x \in X \given \frac{\sqrt{x}}{x^2+1} > 1 }$


(This is actually more complicated than probably needs to be, because it deals with spacing.) Of course there are many ways to use this package to define similar macros.

• First of all, thanks a lot for the answer! Concerning it, I was wondering how to modify it to call – say – the command \Name, and how to get the vertical bar by just inserting $|$ (as in braket, which is very handy), instead of writing \given. – Kolmin Oct 7 '16 at 7:27
• Actually, I figured out how to modify the name, but still I cannot find a way to substitute \given with the simple symbol |. Do you have any idea on how to implement it? Btw, I edited the original question inserting the piece of code from braket. – Kolmin Oct 7 '16 at 9:29
• If you just want to modify the code above from braket, it should suffice to replace all instances of set and set (but not \SetVert and \SetDoubleVert) with name and Name, respectively, and replace \lbrace and \rbrace with the desired left and right brackets. – Emma Oct 7 '16 at 14:44
• To use | in place of \given in the mathtools example I gave, add \providecommand\given{\vert} \catcode\|=\active \def|{\given} to the preamble. Note, however, that this will break usage of || as shorthand for a double vertical line (also achievable with \Vert or \|, which will not be broken) throughout the document. It looks like this is fixed in the braket code, but I haven't been able to adapt the fix to the mathtools setting. – Emma Oct 7 '16 at 14:53
• @Emma If you're replacing \lbrace and \rbrace (from the braket package code) with the desired left and right brackets, also remember that \{ is a synonym for \lbrace and similarly \} is a synonym for \rbrace, so these also need to be replaced. For some reason, the (short) braket package code uses both versions. – Ari Brodsky Jul 6 '18 at 8:44

Following up on Emma's comment, here is a version of \Sequence{...|...} that is similar to \Set from the bracket package. I intentionally shortened the code to remove redundancy now that the \middle command from e-TeX is standard, but I also removed the ability to turn || into \| because I'm only interested in a single | separator.

\NeedsTeXFormat{LaTeX2e}
\documentclass{amsart}
\usepackage{etex, fixltx2e}
\usepackage{braket} %  for the \Set{...|...} command

% want to define \Sequence{...|...} to be similar to \Set of the braket package

{\catcode\|=\active
\xdef\Sequence{\protect\expandafter\noexpand\csname Sequence \endcsname}
\expandafter\gdef\csname Sequence \endcsname#1{\left\langle%
\:{
\mathcode\|32768\let|\SetVert
#1}\:\right\rangle}
}
\def\SetVert{\egroup\;\middle|\;\bgroup}

\begin{document}
$\Sequence{ B^{c^f}_d | d < \omega^2 }$

$\Set{ B^{c^f}_d | d < \omega^2 }$
\end{document}