Significant EDIT: Stimulated by the comments of the users egreg and schtandard, I found a solution to my original problem. Now, the problem has slightly changed, but it is still about the control between text and brackets with the braket page.

As in the title of the question, I would like to modify the package braket (in the link the whole .sty file, which is quite small) to control the space between the brackets and the text.

This question is a follow up of this previous question of mine: Modify braket package for different brackets forms.

Thus, the idea is that I would like to adapt this sty file to make it work with other brackets (as in the previous question) and to have different spacings for all those new brackets. If you are wondering why I want to modify braket instead of writing my own macro, the reason is that doing this would be way above my level (which should not be surprising considering the level of this question).

Here there is an example of what I would like to get in the sty file.


$\Set { a | b }$
$A \Foo { \hspace{-0.1cm} a \hspace{-0.1cm}| \hspace{-0.1cm}b \hspace{-0.1cm} }$


We can call \Foo the command that should correspond to the second line, which should look something like A(a|b).

To get what I want, the line from braket should be modified as follows:

  \xdef\Foo{\protect\expandafter\noexpand\csname Foo \endcsname}
  \expandafter\gdef\csname Foo \endcsname#1{\mathinner
        {\lbrace\,{\mathcode`\|32768\let|\midvert #1}\,\rbrace}}
  \xdef\Foo{\protect\expandafter\noexpand\csname Foo \endcsname}
  \expandafter\gdef\csname Foo \endcsname#1{\left(
        \ifx\SavedDoubleVert\relax \let\SavedDoubleVert\|\fi

\def\FooVert{\@ifnextchar|{\|\@gobble}% turn || into \|

The code above is nothing more than the code from braket regrouped for readability reasons, with:

  1. Foo instead of Set,
  2. \left( and \right) instead of \left\{ and \right\},
  3. and with the horizontal spacing commands \: and \; commented.

This is enough to get one part of the result.

The bit that is missing is the following:

How do we control in braket the space in the line of code A \Foo { a | b } between the letter "A" and the bracket "("?

Here there are two examples of commands that should be created in braket to achieve the following output.

% Command Fou
$A \hspace{3cm} \Set { \hspace{3cm} a \hspace{-0.1cm} | \hspace{-0.05cm} b \hspace{5cm} }$

%Command Fouo
$A \hspace{-0.05cm} \Set { \hspace{-0.05cm} a \hspace{-0.1cm} | \hspace{-0.1cm} b \hspace{-0.05cm} }$

Any help is going to be greatly appreciated!

  • 1
    Would you please add an example showing the space you find too wide?
    – egreg
    Sep 19, 2019 at 10:28
  • @egreg I am sorry but I do not really understand the question. I just would like to have a way to control the space between brackets and text, e.g, to move from this "{ a | b }" to "{ a | b }" to – eventually – this "{a|b}", or to get "{ a | b }", where it is understood that all those instances come from the same line of code $\Set { a | b }$.
    – Kolmin
    Sep 19, 2019 at 10:42
  • [I do not know how to represent here the varying space between the bracket "{" and the "a" (and the same for the other side.]
    – Kolmin
    Sep 19, 2019 at 10:44
  • I got what you meant. I will provide the example above. :)
    – Kolmin
    Sep 19, 2019 at 10:48
  • 1
    Why do you want to use braket at all? It seems to me you want to remove the features it provides. Why not just write \(\{a|b\}\) or define a macro that does that? If you want an explanation of why what you tried did not work, you really should include an MWE showing exactly how you tried it and what did not work. Just describing what you did without actually showing it leaves a lot of room for interpretation (i.e. guessing and misunderstanding).
    – schtandard
    Sep 21, 2019 at 21:33

1 Answer 1


Your questions are still not entirely clear to me, but here is an attempt to answer:

  • While the decision to want to remove all those spaces is rather questionable, if you want to do it, I think it is best to just write a new command than to modify the braket definitions. (After all, you don't really want to use any of it.) This is easily done using xparse with mleftright for the space around the braces.

    \NewDocumentCommand\kolmin{ O{0mu} O{#1} m }{%
      \mleft\{ \mkern #1\relax #3 \mkern #2\relax \mright\}
    \(X \kolmin{a|b} X\)
    \(X \kolmin[10mu]{a|b} X\)
    \(X \kolmin[10mu][5mu]{a|b} X\)
  • The \spacefactor error you got is due to the fact that you forgot to use \makeatletter before your definitions. See this question for an explanation.
  • Since you noted that macro definition is "way over your head", if you are interested in a technical, but not too in-depth description of how macro expansion in TeX works this blog series might be a good starting point. (If anyone knows of a good answer on-site, feel free to comment.)

Regarding your updated request, you can of course define a macro like

\NewDocumentCommand\Fou{ m m }{%
  \hspace{3cm} \Set { \hspace{3cm} #1 \hspace{-0.1cm} | \hspace{-0.05cm} #2 \hspace{5cm} }

to get the output you specified, but that seems like a backwards approach to me. It is easier and cleaner to just not use braket, as shown above, and adjust the spacing to your liking, e.g.

\NewDocumentCommand\Fou{ m m }{%
  \mskip 150mu\relax\mleft\{ \mkern 150mu\relax #1 \middle| \mkern 5mu\relax #2 \mkern 200mu\relax \mright\}%

though this is obviously terrible typography.

  • First of all, I would like to thank you for your effort. Concerning the second and the third bullet, I will study them. Looking around, I already found out what was the conceptual issue behind the error I got, but your answer gave me a way to solve it, plus a reference. Concerning your code, I tried to compile it as it is, but it didn't work. Also, thanks a lot for the "mleftright": I was not aware of that package, which solves exactly the problem I was referring to in my last edit. It is not still clear to me if it is possible to customize the distance with "mleftright".
    – Kolmin
    Sep 22, 2019 at 17:02
  • Concerning accepting the answer, strictly speaking my question was related to "braket" (also as a way to understand the LaTeX code). Thus, I am waiting for an answer that deals only with braket. If it does not come, I will be happy to accept your answer. Again, thanks a lot!
    – Kolmin
    Sep 22, 2019 at 17:03
  • @Kolmin Well, the MWE should compile, unless you are missing some packages. What error messages are you getting? If you want to add some space before and after the braces, you can easily do that by inserting some \mskips (and maybe more optional arguments) into the definition of \kolmin. It is very hard though to answer your question, since it is unclear what you want to achieve.
    – schtandard
    Sep 22, 2019 at 18:50
  • I edited the end to make clear what I would like to achieve.
    – Kolmin
    Sep 23, 2019 at 9:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .