0

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?

4
  • Could you please add a minimal but complete document showing what you have tried? Literally using Z[x] will give you brackets on the same line as Z.
    – siracusa
    May 21 '19 at 11:35
  • 1
    Please, explain how should be this bracket aligned in a case $Z[y]$? or $Z[f]$? Size of brackets and its alignment is depended on content in brackets. The same do \left[ and \right].
    – Zarko
    May 21 '19 at 11:50
  • Okay, so basically what I'd like to get is to align the brackets according to Z, because by using [ ] or \lbrack \rbrack the brackets go a little bit under the Z and I want to avoid this. May 21 '19 at 18:51
  • The brackets used for (La)TeX are designed so that they do not change size if your expression is $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. May 21 '19 at 22:51
2

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}

Screenshot

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.

3
  • One can not deny that it looks terrible. Nice answer
    – user156344
    May 21 '19 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. May 21 '19 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. :-)
    – frougon
    May 21 '19 at 19:45

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.