# LaTeX: An Amazing Pain in the Behind

I love $\LaTeX$, but I also hate it. Once you’ve got everything set up, the ability to just type the content and have everything automatically laid out in a sensible way is amazing. But getting it to do something new can be a real pain for anyone who hasn’t spent years delving into its guts: packages interact in complicated ways and often produce outcomes that you weren’t expecting, and then finding a way to make them produce the correct outcome can eat hours of experimentation.

The problem I had this time initially seemed fairly simple. I wanted something like this:

The purpose is to box off word-lists in a kind of thematic dictionary, i.e. one organised by semantic area instead of alphabetically. Some of these boxes can be quite large, so they also need to be breakable.

My first thought was just to use a definition list, stick it inside a multicol, inside a minipage, and then draw a box around the whole thing with fbox. Job done, right? It looked good… apart from the fact that it wouldn’t break, so longer lists would hop entire pages. Back to the drawing board, then inspiration struck: the problem was the minipage/fbox bit!

OK, what else could I use? The tcolorbox package seemed like it could draw a breakable box, so I tried that: tcolorbox + multicol + definition. That had to work, right? Except it didn’t… because multicol uses some kind of complicated column balancing algorithm and does its own thing when it comes to page breaks, and that in turn meant that it was just an opaque unbreakable block as far as any containing environment was concerned.

Since multicol was the only obvious way to make a standard definition list go horizontal as well as vertical, I tried replacing the list formatting bit next. What with? Experimentation with several packages followed, none doing exactly what I wanted… until I found the tasks package. I’d actually discarded this earlier because all the examples in the docs were of the enumerate/itemize type, and none had words or long text strings as markers, but reading carefully suggested that it might be possible to bend it to my use. I tried supplying multi-letter labels, and the result was overlapping text… until I manually adjusted the spacing settings. Success!

The final code looks like this (the tcolorbox code borrowed from good old Stack Overflow):

\usepackage[most]{tcolorbox}

\newtcolorbox[auto counter]{thematicdictbox}[2][]{%
breakable,
enhanced,
sharp corners,
colback=white,
fonttitle=\bfseries,
title=Box~\thetcbcounter:\ #2,
enlarge bottom at break by=5mm,
enlarge top at break by=5mm,
overlay first={%
\draw[black, line width=0.5mm](frame.south west)--(frame.south east);
\node[anchor=north east] at (frame.south east) {continued on next page};
},
overlay middle={%
\draw[black, line width=0.5mm](frame.south west)--(frame.south east);
\draw[black, line width=0.5mm](frame.north west)--(frame.north east);
\node[anchor=north east] at (frame.south east) {continued on next page};
\node[anchor=south west] at (frame.north west) {continued from previous page};
},
overlay last={%
\draw[black, line width=0.5mm](frame.north west)--(frame.north east);
\node[anchor=south west] at (frame.north west) {continued from previous page};},
#1
}

% OTHER CODE

\begin{thematicdictbox}{Some Words}
\begin{twocolwordlist}
\item[Word 1] Definition 1
\item[Word 2] Definition 2
\item[Word 3] Definition 3
\item[Word 4] Definition 4
\item[Word 5] Definition 5
\item[Word 6] Definition 6
\item[Word 7] Definition 7
\item[Word 8] Definition 8
\item[Word 9] Definition 9
\item[Word 10] Definition 10
\end{twocolwordlist}
\end{thematicdictbox}



The only other enhancement I’d like is to merge the thematicdictbox and twocolwordlist environments into a single environment. But something like this doesn’t work:

\newenvironment{boxtwocol}[1]
{\begin{thematicdictbox}{#1}
\begin{twocolwordlist}}
{\end{twocolwordlist}
\end{thematicdictbox}}


Why not? Who knows! I think it’s something to do with the way that tasks scans the intermediate content for the item markers (\item in this case), but I don’t understand TeX well enough to figure out what’s going horrible wrong.

Just another day in the life of a LaTeX user who doesn’t have a year to spend tearing the crusty old core of the system apart to figure out why it does all the random crap it does.