3

Many roman and sans serif fonts, and the default LaTeX fonts in particular, seem to have a thing with square brackets: they descend a long distance below the baseline, probably in order to "catch" descenders. However, in a lot of cases this looks really odd (at least to me), especially when typesetting things like X[10]:

Weird brackets

For that use case it looks a lot better to me (personally) when the square bracket is centered vertically around the midpoint of the capital letter. Except in the tt font where it already looked fine before and which got broken by the change. I can live with the fact that the g now looks slightly out of place, which was also the case before in the tt version.

Nice brackets

Now I ask more out of curiosity than out of need: Is there a document-based way (i.e. other than adjusting the font files) to shift all square brackets in the current scope (or in the whole document) up bit a certain amount (ideally depending on the current font family and size)? In my limited understanding such a thing would probably require a lot of black magic TeX hackery, breaking many things in the process... or maybe it would not. Maybe one of the wise TeX wizards around here knows the answer.


\documentclass{article}
\newcommand{\R}[1]{\raisebox{0.075em}{#1}}
\begin{document}
\noindent
rm: \textrm{X[10g]}\\
sf: \textsf{X[10g]}\\
tt: \texttt{X[10g]}\\
math: $X[10g]$\\

\noindent
rm: \textrm{X\R[10g\R]}\\
sf: \textsf{X\R[10g\R]}\\
tt: \texttt{X\R[10g\R]}\\
math: $X\R[10g\R]$\\
\end{document}
  • 2
    It's a choice made by the font designer. In particular, in Computer Modern the brackets are vertically symmetric with respect to the formula axis (the line above the base line where the fraction lines sit). – egreg Sep 10 '14 at 22:44
  • Yes, I know that it is a font design decision (though not the formula axis part) and I do acknowledge that it is probably a good decision. But my question is whether it can be automatically overridden using TeX mechanics when desired for some special application. – Fritz Sep 10 '14 at 22:52
  • 2
    Much hackery, I'd say. – egreg Sep 10 '14 at 22:53
  • 1
    I'd just define a command \[ would be good but it's taken:-) that does your \raisebox, making [ active and trying to make it raise itself will break too much (every optional argument for a start) you could try to fix that , but not without breaking something else.... – David Carlisle Sep 10 '14 at 23:21
  • If opentype fonts are an option, the discussion at tex.stackexchange.com/q/170293/7883 may be of interest. – Thérèse Sep 11 '14 at 1:12
1

As David points out in the OP's comments, making the brackets active will break the use of many things, such as optional arguments. So this solution splits the difference. It creates the macros \shftON and \shftOFF to turn the vertically shifted brackets on and off by making them \active or not.

When \shftON is invoked, you can get the brackets you want with the [ and ] characters... and when \shftOFF is invoked, everything reverts to the normal way of doing things. In my MWE, I show this by first demonstrating the \shftON bracket appearances, and then, after turning \shftOFF, I show not only the original brackets in use, but also make use of an optional bracketed argument to show that they are not broken by this technique.

\documentclass{article}
\usepackage{graphicx}% ONLY NEEDED FOR \scalebox DEMO
\setbox0=\hbox{0}
\newlength\htz\newlength\dpz
\htz=\ht0\relax
\dpz=\dp0\relax
\let\svlb[
\let\svrb]
\def\shftlb{\setbox0=\hbox{\svlb}\raisebox{%
  \dimexpr-.5\ht0+.5\htz+.5\dp0-.5\dpz}{\svlb}}
\def\shftrb{\setbox0=\hbox{\svrb}\raisebox{%
  \dimexpr-.5\ht0+.5\htz+.5\dp0-.5\dpz}{\svrb}}
\catcode`[=\active
\catcode`]=\active
\def\shftON{%
  \catcode`[=\active
  \catcode`]=\active
  \def[{\shftlb}%
  \def]{\shftrb}%
}
\catcode`[=12
\catcode`]=12
\def\shftOFF{%
  \catcode`[=12
  \catcode`]=12
}
\begin{document}
\shftON
$X [10] g$\par\textsf{X [10] g}\par\texttt{X [10] g}\par\textrm{X [10] g}
\shftOFF
Revert: \textrm{X [10] g} \scalebox{.35}[.75]{Optional Argument used}
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.