Latex—Square bracket ([) inside a macro causes error

Juliano David Hilario :

I have a program that scrapes many articles from a particular website, I convert the article from HTML to LaTeX with lots of if and elses, but now I can't rescrape them since I've already downloaded 1555+ issues and converted them into tex and it will take alot of time to pull it again and i don't want to put more burden on the server. Now my problem is that some of the article generates a cumbersome form of text, (\tboxsup{\textbf{[Picture on page 16}, \textbf{17]}}) and that causes the LaTeX to complain. In short, how do I escape the brackets to solve my problem?

here is how vim notifies me of the error

I can't really simply wrap manually them with {} because it occurs in random articles. I am planning to use sed to fix them.


mwe

\documentclass{article}

\usepackage[most]{tcolorbox}
\newcommand{\tboxsup}[1]{
\begin{center}
\begin{tcolorbox}[enhanced,
     breakable,
     width=0.75\textwidth,
     colback=white,
     colframe=darkgray,
     colupper=darkgray,
     boxrule=-1pt,
     arc=0pt,
     boxsep=3pt,
     colbacktitle=darkgray,
          title=#1]

}

\begin{document}
\tboxsup{\textbf{[Picture on page 12}, \textbf{13]}}

Egyptian model depicting the preparation of bread and beer
\vspace{.5em}

\textbf{[Credit Line]}
\vspace{.5em}

Su concessione del Ministero per i Beni e le Attività Culturali-Museo Egizio-Torino
\vspace{.5em}

\end{tcolorbox}
\end{center}
\end{document}

Thank you very much!

samcarter_is_at_topanswers.xyz :

The problem is that you try to use a square bracket inside an optional argument. You can hide them by wrapping #1 in an additional group of {}

\documentclass{article}

\usepackage[most]{tcolorbox}
\newcommand{\tboxsup}[1]{
\begin{center}
\begin{tcolorbox}[enhanced,
     breakable,
     width=0.75\textwidth,
     colback=white,
     colframe=darkgray,
     colupper=darkgray,
     boxrule=-1pt,
     arc=0pt,
     boxsep=3pt,
     colbacktitle=darkgray,
          title={#1}]

}

\begin{document}
\tboxsup{\textbf{[Picture on page 12}, \textbf{13]}}

Egyptian model depicting the preparation of bread and beer
\vspace{.5em}

\textbf{[Credit Line]}
\vspace{.5em}

Su concessione del Ministero per i Beni e le Attività Culturali-Museo Egizio-Torino
\vspace{.5em}

\end{tcolorbox}
\end{center}
\end{document}

enter image description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=15464&siteId=1