1

If I use the following code to get an average integral

\documentclass{article}

\usepackage{scalerel}
\usepackage[usestackEOL]{stackengine}

\def\dashint{\,\ThisStyle{\ensurestackMath{%
            \stackinset{c}{.2\LMpt}{c}{.5\LMpt}{\SavedStyle-}{\SavedStyle\phantom{\int}}}%
        \setbox0=\hbox{$\SavedStyle\int\,$}\kern-\wd0}\int}

\begin{document}

    $\dashint f(t)\,dt$

\end{document}

I get this nice result:

enter image description here

However, if I also load the package breqn (no matter where I put the line \usepackage{breqn} in the preamble) it does not work anymore, i.e. I get this strange result:

enter image description here

Is anybody able to figure out why?

0

1 Answer 1

2

It would appear that breqn has a bug which breaks \mathchoice.

Here is the MWE that shows it:

\documentclass{article}
\usepackage{breqn}
\begin{document}
$\mathchoice{Displaystyle}{Textstyle}{Scriptstyle}{scriptscriptstyle}$
\end{document}

enter image description here

The \mathchoice macro is a fundamental TeX command for distinguishing the style of math mode. The above case should yield a "Textstyle" and does so, if breqn is not loaded. It indicates that the code is in \textstyle math mode. However, with breqn loaded, it gives a "Displaystyle" as its output.

The scalerel package cannot function without knowing the actual math style that one resides in, as it uses \mathchoice to decode its \ThisStyle{...\SavedStyle...} syntax.

In the case of the OP's macro, the problem is that, with breqn loaded, the stack inside the dashint macro is setting the \int in display style, even if \dashint is invoked in text style, as in the OP's example.


While I initially showed a manual workaround, the OP reminds me (citing this question: Clash between mhchem and breqn. Any way to dodge or fix?) that one can save the old definition of \mathchoice before loading breqn and then temporarily restore it for the use of \dashint. In that way, the scalerel macros \ThisStyle{...\SavedStyle...} will behave properly.

Here would be that code:

\documentclass{article}

\usepackage{scalerel}
\usepackage[usestackEOL]{stackengine}
\let\oldmathchoice\mathchoice
\usepackage{breqn}
\let\newmathchoice\mathchoice

\def\dashint{\let\mathchoice\oldmathchoice\,\ThisStyle{\ensurestackMath{%
            \stackinset{c}{.2\LMpt}{c}{.5\LMpt}{\SavedStyle-}{%
            \SavedStyle\phantom{\int}}}%
        \setbox0=\hbox{$\SavedStyle\int\,$}\kern-\wd0}\int%
        \let\mathchoice\newmathchoice}

\begin{document}
\centering
    $\dashint_a^b f(t)\,dt$

    \[\dashint_a^b f(t)\,dt\]
\end{document}

enter image description here

2
  • 1
    This answer is illuminating! I think another good workaround could be to save the original version of \mathchoice and temporarily restore it inside the definition of \dashint, as is done in tex.stackexchange.com/questions/96002/… (I tested it and it works!)
    – Mizar
    May 31, 2016 at 15:23
  • @Mizar Thanks. I will edit my answer to reflect it. May 31, 2016 at 15:31

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.