7

If I define a macro which uses a mdframed box, this seems to disable csquotes (red box). But using mdframed directly (i.e., without defining it via a macro), then the csquotes package can do its job just fine (green box).

enter image description here

How can I define an mdframed environment within a macro and also use the nice features of the csquotes package?

References:

Code:

\documentclass{article}

\usepackage{mdframed}
\usepackage{xcolor}

%%% https://tex.stackexchange.com/questions/50712/automatically-convert-quotations-in-the-form-of-abc-to-become-abc
\usepackage{csquotes}
\MakeOuterQuote{"}

\mdfsetup{frametitlerule=true, frametitlerulecolor=brown}

\newcommand{\HelloWorld}{%
    \begin{mdframed}[backgroundcolor=red!25,frametitle={Usage of mdframed via a macro (Quotes Are Incorrect)}]
        "Hello World."
    \end{mdframed}%
}%

\begin{document}

\HelloWorld

\begin{mdframed}[backgroundcolor=green!25,frametitle={Direct usage of mdframed (Quotes Are Correct)}]
    "Hello World."
\end{mdframed}%


\end{document}
3
  • Congratulations for your 100K!
    – egreg
    Commented Jul 22, 2014 at 23:51
  • I second egreg's comment: congrats! Commented Jul 22, 2014 at 23:52
  • @egreg: Thanks. I thought I'd have it a long time ago, but had to force my self to do some "real" work. :-) Congratulations on your imminent 300K! Commented Jul 22, 2014 at 23:52

2 Answers 2

5

The package csquotes performs \MakeOuterQuote{"} by making " active, but it postpones the setting \AtBeginDocument. So, when your \newcommand{\HelloWorld}{...} is processed, the " characters in the replacement text are normal (non active) characters.

If you try adding \show before the first " in the definition, compilation will stop with

> the character ".
\HelloWorld ...ro (Quotes Are Incorrect)}] \show "
                                                  Hello World." \end {mdframed}

If you add \show before " in the “naked” mdframed environment, you'll get

> "=macro:
->\csqQQ {34}.
l.23     \show"
               Hello World."

(and several errors, of course).

So mdframed has nothing to do with this.

\documentclass{article}

\usepackage{mdframed}
\usepackage{xcolor}

\usepackage{csquotes}
\MakeOuterQuote{"}

\mdfsetup{frametitlerule=true, frametitlerulecolor=brown}

\newcommand{\HelloWorld}{%
    \begin{mdframed}[
      backgroundcolor=red!25,
      frametitle={Usage of mdframed via a macro (Quotes Are Correct)}
    ]
        \csqQQ{34}Hello World.\csqQQ{34}
    \end{mdframed}%
}

\begin{document}

\HelloWorld

\begin{mdframed}[
  backgroundcolor=green!25,
  frametitle={Direct usage of mdframed (Quotes Are Correct)}
]
    "Hello World."
\end{mdframed}


\end{document}

enter image description here

2
  • So should I just use `` instead for anything before \begin{document} instead of \csqQQ{34}, or is there an advantage to using \csqQQ{34}? Commented Jul 23, 2014 at 3:47
  • @PeterGrill I see no advantage, it was just to show that the emulation is working.
    – egreg
    Commented Jul 23, 2014 at 8:36
4

If your \newcommand{\HelloWorld} is the last activity before \begin{document} and there are no anothers " in your real code, you should prepend before this command:

\catcode`\"=13

and you needn't to change your definition.

The reason was answered by egreg. You need to have the " active at the time of definition of the \HelloWorld.

2
  • Yeah that works, but only if I set the \catcode outside of \newcommand. Would have used this solution if I could put this _inside the mdframed environment. Commented Jul 23, 2014 at 16:14
  • catcodes are used during tokenization process, i.e. when TeX reads text from file. No from macro. Tokens are stored to the macro body and they are never changed (exceptions exist). If you really need to do re-tokenization during macro processing, you can try to use \scantokens primitive from eTeX.
    – wipet
    Commented Jul 23, 2014 at 20:00

You must log in to answer this question.

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