Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

%%% http://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}
share|improve this question
    
Congratulations for your 100K! –  egreg Jul 22 at 23:51
    
I second egreg's comment: congrats! –  Gonzalo Medina Jul 22 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! –  Peter Grill Jul 22 at 23:52

2 Answers 2

up vote 5 down vote accepted

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

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

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.

share|improve this answer
    
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. –  Peter Grill Jul 23 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 Jul 23 at 20:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.