TransWikia.com

LaTeX Error: begin{tcolorbox} on input line x ended by end{myenv} when using new environment

TeX - LaTeX Asked on July 8, 2021

Defining a new environment with a tcolorbox with some options strangely leads to a compilation failure that disappears if I remove [hbox]

documentclass{article}

usepackage{tcolorbox}

newenvironment{myenv}
{begin{tcolorbox}[hbox]}
  {end{tcolorbox}}

begin{document}

begin{myenv}
  blah
end{myenv}

end{document}

I can’t define tcbset{capture=hbox} because it’s the only option that’s protected from tcbset

One Answer

In some cases in environments, you need to use the macro form tcolorbox and endtcolorbox, instead of the standard begin...end approach.

documentclass{article}

usepackage{tcolorbox}

newenvironment{myenv}
{tcolorbox[hbox]}
  {endtcolorbox}

begin{document}

begin{myenv}
  blah
end{myenv}

end{document}

enter image description here

Correct answer by Steven B. Segletes on July 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP