3
  1. I want the text in a {tcolorbox} to exhibit the same paragraph style as the main body. As far as I know (as per the first reference) this requires using \RestoreParskip:

    \newcommand*{\RestoreParskip}{%
      \setlength{\parskip}{\currentparskip}%
      \setlength{\parindent}{\currentparindent}%
    }%
    

    where \currentparskip and \currentparindent needs to be initialized before the {tcolorbox}.

    From the documentation, this appears to be exactly what parbox=false is intended to do:

    If the key value is set to false, the normal main text behavior is restored.

    However, this feature is marked as experiemntal as of 2015-10-14 with the caveat:

    In some situations, this has some unwanted side effects. It is recommended that you use this experimental setting only where you really want to have this feature.

    As I defintely want the same paragraph spacing inside {tcolorbox}, it seems I should use this.

  2. Secondly, using hyphenationfix=true seems to be useful:

    Long words at the beginning of paragraphs in very narrow boxes will not be hyphenated using pdflatex. This problem is circumvented by applying the hyphenationfix option.

    However, there is a warning:

    enter image description here


Using the example text given in the documentation, one can see that parbox=false, hyphenationfix=true together don't seem to work (see 3. in the output of the MWE). I can fix this by leaving parbox=true using \RestoreParskip manually (see 4).

Results without {parskip} and with {parskip}:

enter image description here enter image description here

Questions:

  1. What else is parbox=false doing (besides the \RestoreParskip functionality) that causes it to fail with hyphenationfix=true?
  2. What functionality am I losing by manually using \RestoreParskip?
  3. When will parbox=false functionality leave the experimental designation? I realize that this particluar question can only be answered by the package author, but as I have experienced the pain of having experimental features removed, it would be good to know if this is still really experimental or just that the documentation has not been updated.

Notes:

  • For now, I do not require breakable=true, but might need it in the future. In case it is relevant, comments addressing these cases separately would be useful.

References:

Code:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage[textwidth=4cm]{geometry}

%\usepackage{parskip}% Needs to also work with parskip

\newlength{\currentparskip}
\newlength{\currentparindent}
\setlength{\currentparskip}{\parskip}
\setlength{\currentparindent}{\parindent}

\newcommand*{\RestoreParskip}{%
    \setlength{\parskip}{\currentparskip}%
    \setlength{\parindent}{\currentparindent}%
}%

\newcommand*{\Mytext}{%
    Rechnungsadjunktentochter.\par
    Statthaltereikonzipist.
}

\begin{document}
\begin{tcolorbox}[title={1. Default}]
    \Mytext
\end{tcolorbox}

\begin{tcolorbox}[hyphenationfix, title={2. hyphenationfix}]
    \Mytext
\end{tcolorbox}

\begin{tcolorbox}[hyphenationfix, parbox=false, title={3. hyphenationfix, parbox=false}]
    \Mytext
\end{tcolorbox}

\setlength{\currentparskip}{\parskip}
\begin{tcolorbox}[
    hyphenationfix, 
    before upper=\RestoreParskip\noindent,
    title={4. hyphenationfix, \texttt{\string\RestoreParskip}},
    ]
    \Mytext
\end{tcolorbox}

\end{document}
2
  • Definitely nice example words :)
    – TeXnician
    Commented Dec 28, 2018 at 17:57
  • @TeXnician: :-) I assumed if the words were good enough for the documentation, then they were good enough for a question. Commented Dec 29, 2018 at 2:58

1 Answer 1

4

parbox=false works quite differently to your \RestoreParskip: it doesn't reset two length, but replace the call to \@parboxrestore which would do this

\let\if@nobreak\iffalse
\let\if@noskipsec\iffalse
\let\par\@@par
\let\-\@dischyph
\let\'\@acci\let\`\@accii\let\=\@acciii
\parindent\z@ \parskip\z@skip
\everypar{}%
\linewidth\hsize
\@totalleftmargin\z@
\leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip
\parfillskip\@flushglue
\lineskip\normallineskip
\lineskiplimit\normallineskiplimit
\baselineskip\normalbaselineskip
\sloppy
\let\\\@normalcr

by this

 \noindent%
 \linewidth\hsize%
 \@totalleftmargin\z@%
 \leftskip\z@skip%
 \rightskip\z@skip%
 \@rightskip\z@skip%
  1. Important for your first question is the additionally \noindent: It should suppress the indent in the first line but means that the paragraph has already started before the hyphenationfix can kick in (which uses a \everypar trick). So add a \hspace{0pt} yourself for the first paragraph.

  2. The main difference is that with your \RestoreParskip, \sloppy is active. The other settings from the standard \@parboxrestore could be relevant in some cases, but I didn't analyze them.

2
  • What activates \sloppy in this case? Commented Dec 29, 2018 at 2:55
  • The default \@parboxrestore contains \sloppy. Commented Dec 29, 2018 at 16:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .