3

I want to use many examples that I had already written them in several files looking like

\begin{ejemplo}
  {\label{ex:0xx}}
  {Pregunta}
  {Respuesta}
\end{ejemplo}

with tcolorbox to obtain the figure below, I need a result like the figure below.

I want

that I make with this code:

\documentclass{article}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable,theorems}
\newtcbtheorem{TcbEje}{Ejemplo \thesection.}
    {breakable, enhanced,label separator=-,
    attach boxed title to top left={xshift=3mm, yshift=-3mm, yshifttext=-1mm},
    fonttitle=\bfseries, coltitle=black!100, colbacktitle=white!100,
    colback=white!100, colframe=orange!50,
    separator sign none, description delimiters parenthesis,
    description font=\mdseries}{th}
\NewDocumentEnvironment{ejemplo}{ O{} O{} } % two optional arguments
{\TcbEje{#1}{#2}}
{\endTcbEje}


\begin{document}
\section{Sección 1}
    \begin{ejemplo}[][J:cero]
        \emph{pregunta}
        \tcblower
        Respuesta
    \end{ejemplo}

Como se ve en el ejemplo \thesection.\ref{th-J:cero}
\end{document}

But I can't find how to pass 3 arguments to a \newtcbtheorem. I have hundreds examples called ejemplo for that is impractical to edit one by one.

4
  • 1
    Please don't post code fragments. Instead put the fragments into a compilable document that people can play with.
    – Alan Munn
    Commented Dec 14, 2023 at 16:20
  • edited, @AlanMunn, thanks for the advice. (but now I lost the figure)
    – JOM
    Commented Dec 14, 2023 at 18:23
  • 1
    Sorry but this is still fragments. Put everything into an actual minimal document that compiles.
    – Alan Munn
    Commented Dec 14, 2023 at 18:27
  • 1
    @AlanMunn, thank you, for your patience
    – JOM
    Commented Dec 15, 2023 at 11:31

1 Answer 1

2

I would use find and replace (or sed) to change the source. With sed or similar, you could process many files with a single command, if necessary. While you could transform the source completely, I might just remove the \label{s and matching }s, redefining the custom environment to take three mandatory arguments.

For example,

sed --in-place=backup '/\\begin{ejemplo}/,/\\end{ejemplo}/s/\\label{\([^}]*\)}/\1/' <list of files>

[To check for surprises, remove --in-place=backup to see what this does to a file on standard out. If you miss something, each file will have a backup copy with the suffix backup.]

If that is not an option, you can remove the \label{} in the definition of the environment, using an 'argument processor' (documented in usrguide.pdf).

For example,

\documentclass{article}
% ateb: https://tex.stackexchange.com/a/705068/ addaswyd o gwestiwn JOM: https://tex.stackexchange.com/q/704992/
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable,theorems}
\newtcbtheorem{TcbEje}{Ejemplo \thesection.}
    {breakable, enhanced,label separator=-,
    attach boxed title to top left={xshift=3mm, yshift=-3mm, yshifttext=-1mm},
    fonttitle=\bfseries, coltitle=black!100, colbacktitle=white!100,
    colback=white!100, colframe=orange!50,
    separator sign none, description delimiters parenthesis,
    description font=\mdseries}{th}
\NewDocumentEnvironment{tejemplo}{ O{} O{} } % two optional arguments
{\TcbEje{#1}{#2}}
{\endTcbEje}
\NewDocumentEnvironment{ejemplo}{ >{\delabelargument} m m m }
{%
  \begin{TcbEje}{}{#1}
    \emph{#2}
    \tcblower
    #3
}{%
  \end{TcbEje}%
}
\ExplSyntaxOn
\cs_new_protected_nopar:Npn \delabelargument #1
{
  \tl_set:Nn \ProcessedArgument { #1 }
  \regex_replace_once:nnN { ^\c{label}\B\(.*\)\E } {\1} \ProcessedArgument
}
\ExplSyntaxOff
\begin{document}
\section{Sección 1}
\begin{tejemplo}[][J:cero]
  \emph{pregunta}
  \tcblower
  Respuesta
\end{tejemplo}
\begin{ejemplo}
  {ex:0xx}
  {Pregunta}
  {Respuesta}
\end{ejemplo}

Como se ve en el ejemplo \thesection.\ref{th-J:cero} \ref{th-ex:0xx}
\end{document}

produces the same output (modulo numbering) for the two environments

same output modulo numbering

3
  • Perfect! Thanks @cfr
    – JOM
    Commented Dec 15, 2023 at 18:45
  • I use \label{xxx} because it is the way that Texstudio tells me in the left panel to visibly all of them
    – JOM
    Commented Dec 15, 2023 at 18:51
  • @JOM Personally, I wouldn't alter my code to please my text editor (except for additions of comments of whatever), but obviously that's a decision only you can make.
    – cfr
    Commented Dec 15, 2023 at 19:30

You must log in to answer this question.

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