Envuelva el entorno mdframed en un comando

Envuelva el entorno mdframed en un comando

Creé (copié) un entorno simple para crear un marco alrededor de un fragmento de texto. El entorno utiliza el mdframesentorno para encuadrar el contenido y una macro simple changemarginque se utiliza para agregar un espacio en blanco a la izquierda y a la derecha del cuadro.

\documentclass{article}
\usepackage[utf8]{inputenc}

% mdframe: put a certain amount of text in a box
\usepackage[framemethod=default]{mdframed}
\usepackage{showexpl}
\mdfdefinestyle{exampledefault}{
    rightline=true,
    innerleftmargin=10,
    innerrightmargin=10,
    frametitlerule=true,
    frametitlerulecolor=black,
    frametitlebackgroundcolor=white,
    frametitlerulewidth=1pt,
}

% macro to change margins
\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist

% custom environment
\newenvironment{Boxed}[1]
{
    \begin{changemargin}{2cm}{2cm} 
    \begin{mdframed}[style=exampledefault, frametitle={#1}]
}
{
    \end{mdframed}
    \end{changemargin}
}

\usepackage{lipsum} % add some text

\begin{document}
    \lipsum
    \begin{Boxed}{I'm the title}
        I'm the content. I've a nice frame around me.
    \end{Boxed}
\end{document}

Este es el resultado. Funciona perfectamente. ingrese la descripción de la imagen aquí

Mi pregunta es, ¿puedo usar mi entorno como un comando?

\Boxed{title}{content}

Respuesta1

De hecho, es posible utilizar un mdframedentorno dentro de un comando si está incluido en un BoxedInternalentorno interno.

He mejorado el ejemplo con un argumento opcional para el BoxedInternalentorno y \Boxedla macro.

La pregunta es si estos comandos contenedores son útiles en general.

\documentclass{article}

\usepackage[xcolor]{mdframed}

\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist

\mdfdefinestyle{exampledefault}{backgroundcolor=yellow!10!white}

\newenvironment{BoxedInternal}[2][]
{%
  \begin{changemargin}{0cm}{0cm}%
    \begin{mdframed}[style=exampledefault, frametitle={#2},#1]
    }{%
    \end{mdframed}%
  \end{changemargin}%
}

\newcommand{\Boxed}[3][]{%
  \begin{BoxedInternal}[#1]{#2}
    #3
  \end{BoxedInternal}%
}

\begin{document}

\Boxed{Foo}{Foobar}


\end{document}

ingrese la descripción de la imagen aquí

información relacionada