I want to write Z[x] with those brackets alligned with the Z. I've tried using \lbrack
and \rbrack
but the result is basically the same, so what's the best way to force it to stay on the same line?
1 Answer
Welcome to TeX.SX! It seems to me this is a matter of font choice. That said, here is a way to align the “bottom” of brackets with the base line without changing fonts:
\documentclass{article}
\usepackage{graphicx}
\makeatletter
\newcommand*{\raisedChar}[1]{%
\setbox\z@=\hbox{#1}%
\leavevmode
\raise\dp\z@\box\z@
}
\newcommand*{\@TextOrMathOpening}[1]{%
\TextOrMath{#1}{\mathopen{#1}}%
}
\newcommand*{\@TextOrMathClosing}[1]{%
\TextOrMath{#1}{\mathclose{#1}}%
}
\newcommand*{\raisedOpeningBracket}{%
\@TextOrMathOpening{\raisedChar{[}}%
}
\newcommand*{\raisedClosingBracket}{%
\@TextOrMathClosing{\raisedChar{]}}%
}
\newlength{\widthOfOpeningBracket}
\newlength{\widthOfClosingBracket}
\newlength{\heightOfZ}
\settowidth{\widthOfOpeningBracket}{[}
\settowidth{\widthOfClosingBracket}{]}
\settoheight{\heightOfZ}{Z}
\newcommand*{\scaledAndRaisedOpeningBracket}{%
\@TextOrMathOpening{%
\resizebox{\widthOfOpeningBracket}{\heightOfZ}{\raisedChar{[}}%
}%
}
\newcommand*{\scaledAndRaisedClosingBracket}{%
\@TextOrMathClosing{%
\resizebox{\widthOfClosingBracket}{\heightOfZ}{\raisedChar{]}}%
}%
}
\makeatother
% Abbreviations
\let\OB\raisedOpeningBracket
\let\CB\raisedClosingBracket
\let\sOB\scaledAndRaisedOpeningBracket
\let\sCB\scaledAndRaisedClosingBracket
\begin{document}
Z[x]\quad $Z[x]$
\medskip
Z\OB x\CB\quad $Z\OB x \CB$
\medskip
Z\sOB x\sCB\quad $Z\sOB x \sCB$
\end{document}
It feels a bit hackish, though. I don't propose making [
and ]
active characters, as that would break too many things, but you could choose a pair of Unicode characters and proceed with either \newunicodechar
as in this message or with \DeclareUnicodeCharacter
as in that message.
-
One can not deny that it looks terrible. Nice answer– user156344Commented May 21, 2019 at 11:54
-
That's actually a bit extreme but in someway it is what I need. I mean, the last two examples are close to what I asked, because you aligned the lower part of the brackets to the Z but to that, the upper part now is too high. I guess that with the code you gave one could perfectly align the brackets accordingly to the dimension of the Z. Commented May 21, 2019 at 18:57
-
I've added macros that additionally scale the brackets in the vertical direction so that they have the same height as a Z. Please use the tick mark on the left if this answers your question. :-)– frougonCommented May 21, 2019 at 19:45
Z[x]
will give you brackets on the same line asZ
.$Z[y]$
? or$Z[f]$
? Size of brackets and its alignment is depended on content in brackets. The same do\left[
and\right]
.$Z[y]$
or a subscript is involved. "Text" brackets often are designed to not extend below the baseline, but that isn't appropriate for math.