2

I'm listing code with the minted package and drawing the box around it using the tcolorbox package. However, there are two ways to do it, and I don't know which one is best.

To list code that resides in a separate file, you can either (a) use the tcbinputlisting command or (b) wrap the inputminted command in a tcolorbox environment.

To list code that is put into the LaTeX source itself, you can either (a) use the tcblisting environment or (b) wrap the minted environment in a tcolorbox.

Is it better to use (a) or (b)? Is one more capable than the other? If not, which method is considered most modern, clean and nice?

5

I think, the core of the question is: Should I use

  • (a) the macros provided by the minted library of tcolorbox,
  • (b) the base tcolorbox package without the minted library but with the macros from the minted package.

The answer will depend on your special application and will also be opinion-based to a certain degree, but I will try to give the pros and cons.

(a) Using the minted library of tcolorbox:

  • Pro: The library provides shortcut macros which allow to write a compact source code. The option settings for minted are melted into the tcolorbox options which allows common settings (you may call that clean). New boxed listings (numbered or not) are created easily by the environment creation macros of the library. There is special support, if the minted code is a LaTeX source which should be also be displayed compiled.
  • Con: The library macros enwraps the minted macros which may hide some (future) functionality of minted. The box content is filled automatically; individual mixtures of e.g. source+text+source are not covered.

(b) Using the base tcolorbox plus macros from the minted library.

  • Pro: Full flexibility for the box content. All (future) minted capabilities can be used directly.

  • Con: Longer and more complex source code. Option settings for tcolorbox and minted have to be done separately.

Why was the minted/listings library created? Because I had tons of examples using the (b) method which all had the same ever-repeating structure. With the library, they are much shorter and better readable. But, my examples mostly contained source code plus compiled text; there, the advantage is greater than just displaying source code.

Finally: There is no need to use either (a) or (b). Both can be used in parallel. I use the (a) method for most cases. If a box needs more flexibility (e.g. two source codes in one box), I switch to (b) for this box.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.