3

I'm currently using the following macro:

\def\norm#1{\left\|#1\right\|}

Is it possible to redefine \| so that \|\frac{a}{b}\| produces the same output as \norm{\frac{a}{b}}?

Why? Not only I find easier and clearer to write \|\frac{a}{b}\|, but, most importantly, I realized my text editor can display \| as the unicode norm symbol, which really improves readability.

1 Answers1

2

I recommend against redefining things like \|, but it can be done, if it is only to be used in this paired-delimiter context. (The original definition of \| is now saved in \svvert). As egreg notes in a comment, nesting also causes problems, unless the nested terms are grouped.

\documentclass{article}
\let\svvert\|
\def\norm#1{\left\svvert#1\right\svvert}
\def\|#1\|{\norm{#1}}
\begin{document}
\[
\|\frac{A}{B}\|
\]
\end{document}

enter image description here

  • 2
    Which of course would fail in cases such as $\|\|A\| B\|=\|A\| \|B\|$ – egreg Oct 28 '15 at 15:37
  • What would I have to do if I wanted to redefine the macros \left\{#1\right\}? I can't handle those braces... – Ktree Feb 02 '16 at 16:14
  • @Ktree I don't recommend, for the same reasons cited in the answer, but \documentclass{article} \let\svlb\{ \let\svrb\} \def\emb#1{\left\svlb#1\right\svrb} \def\{#1\}{\emb{#1}} \begin{document} \[ \{\frac{A}{B}\} \] \end{document} – Steven B. Segletes Feb 02 '16 at 18:08
  • @StevenB.Segletes thanks a lot, I know it's not good to redefine \left or \right and I won't do that. The reason why I'm thinking of that is that I redefined my matrix environments like in http://tex.stackexchange.com/a/28452/92996 for beamer presentations. Unfortunatelly, there are some parts where I use \left[...\right] (or \{\}) (e.g. to surround arrays). Now I tried to sort of redefine this, but I think there is no other way than introducing a new command, e.g. \leftbrack...\rightbrack. Or do you know a way? – Ktree Feb 03 '16 at 06:58
  • @Ktree I strongly recommend introducing a uniquely named command to achieve what it is you desire. That is the preferred practice for LaTeX. – Steven B. Segletes Feb 03 '16 at 10:53