\NewTColorBox condicional con diferentes opciones para tcblower

\NewTColorBox condicional con diferentes opciones para tcblower

He creado un archivo NewDocumentEnvironmentpara imprimir secciones con formato diferente para un problema y su solución (y con un comentario opcional en el título):

\documentclass[10pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{geometry}
 \geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }
\usepackage{parskip}
\usepackage{tcolorbox}
\usepackage{lipsum}
\tcbuselibrary{skins,xparse,breakable}

\newcounter{problem}

\NewDocumentEnvironment{newprob}{o m +m}
{ % beginning code
    \refstepcounter{problem}
    \IfNoValueTF{#1}{ % start of true statement
    \begin{tcolorbox}[skin=bicolor,
    breakable,
    title=\textbf{Problem~\theproblem:},
    colframe=black!50!white,
    colback=black!20!white,
    colbacklower=black!5!white]
    {#2}    
    \tcblower\vskip-\baselineskip
    \tcbsubtitle[before skip=0pt]%
    {\textbf{Solution:}}
    {#3}
    \end{tcolorbox}
    } % end of true statement
    { % start of false statement
    \begin{tcolorbox}[skin=bicolor,
    breakable,
    title=\textbf{Problem~\theproblem:}~(#1),
    colframe=black!40!white,    
    colback=black!20!white,
    colbacklower=black!5!white]
    {#2}    
    \tcblower\vskip-\baselineskip
    \tcbsubtitle[before skip=0pt]%
    {\textbf{Solution:}}
    {#3}
    \end{tcolorbox} 
    } % end of false statement
}  %end code

\begin{document}
\begin{newprob}
    {
        This is one problem...
    }
    {
        ... and this is one answer.
    }
\end{newprob}

\begin{newprob}[special]
    {
        This is a speacial problem...
    }
    {
        ... and this is a special answer.
    }
\end{newprob}

\end{document}

El resultado se muestra a continuación.

ingrese la descripción de la imagen aquí

Idealmente me gustaría lograr el mismo resultado usando \NewTColorBox; sin embargo, no he podido entender cómo incorporar los diferentes requisitos de formato para el cuerpo superior e inferior de tcolorboxy los condicionales. Me pregunto si alguien con más experiencia tcolorboxpodría proporcionar una solución.

Respuesta1

No quieres un entorno, sino un comando. Y no es necesario duplicar el código: simplemente escriba condicionalmente el argumento opcional, si se proporciona, en el lugar apropiado.

\documentclass[10pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{geometry}
 \geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }

\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse,breakable}

\newcounter{problem}

\NewDocumentCommand{\newprob}{o +m +m}{%
  \refstepcounter{problem}
  \begin{tcolorbox}[
    skin=bicolor,
    breakable,
    title=\textbf{Problem~\theproblem:}\IfValueT{#1}{~(#1)},
    colframe=black!50!white,
    colback=black!20!white,
    colbacklower=black!5!white
  ]{#2}%
    \tcblower\vskip-\baselineskip
    \tcbsubtitle[before skip=0pt]%
    {\textbf{Solution:}}{#3}
  \end{tcolorbox}
}

\begin{document}

\newprob
    {
        This is one problem...
    }
    {
        ... and this is one answer.
    }

\newprob[special]
    {
        This is a speacial problem...
    }
    {
        ... and this is a special answer.
    }

\end{document}

Quizás también sea posible con \NewTColorBox, pero ¿para qué molestarse?

ingrese la descripción de la imagen aquí

información relacionada