I am planning to move to Context, however, the fact that I'll miss some of LaTeX packages (especially tcolorbox) feels sad. That's why I asked such a question.
Asked
Active
Viewed 1,342 times
1 Answers
7
You can emulate tcolorbox sufficiently well with framed, framedtext, and the MetaFun overlay mechanism.
\startuseMPgraphic{mp:tcolorbox}
path p ; numeric w, h, o ;
w := OverlayWidth ; h := OverlayHeight ; o := BodyFontSize ;
p := ((0,0) -- (0,h+2o) -- (w,h+2o) -- (w,0) -- cycle) cornered (o) ;
fill p withcolor OverlayColor ;
draw p withcolor OverlayLineColor withpen pencircle scaled OverlayLineWidth ;
p := ((0,h) -- (0,h+2o) -- (w,h+2o) -- (w,h) -- cycle) cornered (o) ;
filldraw p -- cycle withcolor OverlayLineColor ;
draw textext.rt(\MPstring{tcolorbox}) shifted (o,h+o) withcolor white ;
setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic
\defineoverlay[tcolorbox][\useMPgraphic{mp:tcolorbox}]
\define\setframetitle
{\setMPtext{tcolorbox}{\strut\framedparameter{title}}}
\defineframedtext
[tcolorbox]
[frame=off,
background=tcolorbox,
backgroundcolor=white,
framecolor=darkred,
rulethickness=2pt,
extras=\setframetitle]
\starttext
\starttcolorbox
[title={Knuth},
backgroundcolor=lightgray]
\samplefile{knuth}
\stoptcolorbox
\stoptext
Henri Menke
- 109,596
-
Thank you, but is it possible to make breakable boxes like in
tcolorboxis breakable boxes and being cutomized by tikz that I am familiar with (Maybe I should learn some of MetaFun for such a purpose). – Muhammed Hashim Apr 23 '19 at 03:22 -
2@MuhammedHashim Yes, you can also have breakable boxes with
textbackground, see e.g. this answer: https://tex.stackexchange.com/a/377261. Customization with TikZ instead of MetaFun is not possible. ConTeXt is tightly coupled to MetaFun. – Henri Menke Apr 23 '19 at 03:55 -
2@HenriMenke: It is possible to use customization for framed with TikZ instead of Metapost. See https://mailman.ntg.nl/pipermail/ntg-context/2012/069802.html It is just a matter of providing a few nice helper macros. – Aditya Apr 23 '19 at 13:06
-
@Aditya That looks helpful. You should post it as an additional answer. – Henri Menke Apr 23 '19 at 20:24

tcolorboxcode, it seems that it could be made format-independent with moderate effort. Some stuff likelistingssupport would have to stay LaTeX-only, but PGF/TikZ does that too. – Henri Menke Apr 23 '19 at 07:33