2

I want to use quotation marks in equations (using \begin{equation} ... \end{equation}) and I want them to be adapted to the height of the text in between. Something like:

\begin{equation}
    x = \left''\frac12\right``
\end{equation}

or

\begin{equation}
    x = \Big{''}\frac12\Big{``}
\end{equation}

But none of these two, not any other I could attempt worked like I wanted.

Please, if someone can help.

0

2 Answers 2

3

You raise quotes the required amount, but never lower them.

\documentclass{article}

\makeatletter

\NewDocumentCommand{\mathquotes}{m}{% #1 = subformula to be quoted
  {\mathpalette\mathquotes@{#1}}%
}

\newcommand{\mathquotes@}[2]{%
  \begingroup
  \sbox\z@{$\m@th#1#2$}%
  \sbox\tw@{\normalfont``}%
  \ifdim\ht\tw@>\ht\z@
    \dimen@=0pt
  \else
    \dimen@=\dimexpr\ht\z@-\ht\tw@\relax
  \fi
  \raisebox{\dimen@}{\normalfont``}\box\z@\raisebox{\dimen@}{\normalfont''}%
  \endgroup
}

\makeatother

\begin{document}

\[
\mathquotes{a}+\mathquotes{\frac{1}{2}}
\]

\end{document}

enter image description here

Here's a version where \mathquotes* uses single quotes.

\documentclass{article}

\makeatletter

\NewDocumentCommand{\mathquotes}{sm}{{% #2 = subformula to be quoted
  \IfBooleanTF{#1}{%
    \mathpalette\mathquotes@{{`}{#2}{'}}%
  }{%
    \mathpalette\mathquotes@{{``}{#2}{''}}%
  }%
}}

\newcommand{\mathquotes@}[2]{\mathquotes@@#1#2}
\newcommand{\mathquotes@@}[4]{%
  \begingroup
  \sbox\z@{$\m@th#1#3$}%
  \sbox\tw@{\normalfont#2}%
  \ifdim\ht\tw@>\ht\z@
    \dimen@=0pt
  \else
    \dimen@=\dimexpr\ht\z@-\ht\tw@\relax
  \fi
  \raisebox{\dimen@}{\normalfont#2}\box\z@\raisebox{\dimen@}{\normalfont#4}%
  \endgroup
}

\makeatother

\begin{document}

\[
\mathquotes{a}+\mathquotes{\frac{1}{2}}+\mathquotes*{A}
\]

\end{document}

enter image description here

1
  • Thank you for your answer :D
    – Ziad
    Mar 23, 2023 at 18:39
2

Quotation marks are not delimiters so you can't use \left...\right or \Big and friends. And these only work on single characters, which '' is not.

This solution will raise the quotation marks to the height of the fraction:

raised quotation marks

\catcode`\@=11
% \raisearound{<left material>}{<right material>}{<center material>}
\def\raisearound#1#2#3{\mathpalette\raisearoundA{{#1}{#2}{#3}}}
\def\raisearoundA#1#2{\raisearoundB#1#2}
\def\raisearoundB#1#2#3#4{{%
    \setbox0=\hbox{#2}%
    \setbox1=\hbox{#3}%
    \setbox2=\hbox{$\m@th#1#4$}%
    \raise\dimexpr\ht2-\ht0\relax\box0%
    \copy2%
    \raise\dimexpr\ht2-\ht1\relax\box1%
}}
\catcode`\@=12

$A+\raisearound{``}{''}{\frac12}+B$

$\displaystyle A+\raisearound{``}{''}{\frac12}+B$
1
  • Thank you for your answer :D
    – Ziad
    Mar 23, 2023 at 18:39

You must log in to answer this question.

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