Package csquotes does not seem to work within a mdframed box defined via a macro

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:

  • Automatically convert quotations in the form of "abc" to become “abc".

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}

Solutions Collecting From Web of "Package csquotes does not seem to work within a mdframed box defined via a macro"

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

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.