3

First of all, here is my MWE:

\documentclass[oneside, openright, 12pt]{book}

\usepackage{enumitem}

\newenvironment{boldenumerate}
{\begin{enumerate}[label=\textbf{\arabic*.}]}
    {\end{enumerate}}

\newcommand\bolditem[1]{\item \textbf{#1}}

\begin{document}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

\begin{boldenumerate}
    \bolditem{Caption:} xxx fsdkjnfdskf sdnjdsnfmdns dnsmfndsmfnds nfdsmn fmssadasd-dnfm nsdmfn msndmnsdbfinsfdn
    \bolditem{Another caption:} yy
\end{boldenumerate}

\end{document}

In general, it does exactly what I want it to do. But unfortunately it exceeds the right side edge in some cases when hyphenation gets invoked:

enter image description here

Is there something wrong with my environment definition?

  • There is nothing wrong. There does not exist hyphernation patterns for what ever that language is. Btw you can use the kantlipsum package and its \kant comnand to get sample text in English (which is the default hyphernation pattern) – daleif Feb 11 '18 at 15:24
  • TeX never attempts hyphenation at “words” containing an explicit hyphen. – egreg Feb 11 '18 at 15:25
  • 1
    No, that doesn't happen if you don't ask for ragged right typesetting. – egreg Feb 11 '18 at 15:44
  • 1
    @cfr It's a precise choice made by Knuth. And I endorse it: in these cases, judgment has to be used for where to place a discretionary hyphen. – egreg Feb 12 '18 at 0:15
  • 1
    @cfr: Yes, after saying \usepackage[italian]{babel} \setactivedoublequote, all I have to do is to write, say, economico"-sociologico"-geopolitico, and TeX will utilize all the hyphenation points it knows about in the line breaking algorithm; indeed, \showhyphens{economico"-sociologico"-geopolitico} returns eco-no-mi-co-so-cio-lo-gi-co-geo-po-li-ti-co. I see no reason why the same could not be done in English too, but apparently nobody has ever felt this necessary, at least until now… :-) – GuM May 25 '18 at 23:46
2

With the code you showed us you have to add possibly breaks to add by your own, if a word already contains an hyphen. So instead your fmssadasd-dnfm write for example fms\-sad\-asd-dnfm ( I guessed two possitions for a valid -) or for your word with hyphen in your answer Pop-Operationen write Pop-Ope\-ra\-tio\-nen.

The complete MWE is:

\documentclass[oneside, openright, 12pt]{book}

\usepackage{enumitem}

\newenvironment{boldenumerate}
{\begin{enumerate}[label=\textbf{\arabic*.}]}
    {\end{enumerate}}

\newcommand\bolditem[1]{\item \textbf{#1}}

\begin{document}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy 
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam 
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet 
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit 
amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam 
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, 
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea 
rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem 
ipsum dolor sit amet.

\begin{boldenumerate}
  \bolditem{Caption:} xxx fsdkjnfdskf sdnjdsnfmdns dnsmfndsmfnds 
    nfdsmn fms\-sad\-asd-dnfm nsdmfn msndmnsdbfinsfdn
  \bolditem{Caption:} xxx fsdkjnfdskf sdnjdsnfmdns dnsmfndsmfnds 
    nfd Pop-Ope\-ra\-tio\-nen nsdmfn msndmnsdbfinsfdn
  \bolditem{Another caption:} yy
\end{boldenumerate}

\end{document}

and gives you the result:

enter image description here

Solution for German language

It seems you are a German using German language: Then you will use package babel in your code for language support. With babel you can use "= to mark a fixed, always printed - in an german word, but other (automatic) hyphenations are allowed too.

So you will get with the following german MWE

\documentclass[oneside, openright, 12pt]{book}

\usepackage[ngerman]{babel} % <=========================================

\usepackage{enumitem}
\usepackage{blindtext} % to get dummy text in used language, if supported

\newenvironment{boldenumerate}
{\begin{enumerate}[label=\textbf{\arabic*.}]}
    {\end{enumerate}}

\newcommand\bolditem[1]{\item \textbf{#1}}


\begin{document}

\blindtext

\begin{boldenumerate}
  \bolditem{Caption:} xxx fsdkjnfdskf sdnjdsnfmdns dnsmfndsmfnds 
    nfdsmn fmssadasd"=dnfm nsdmfn msndmnsdbfinsfdn % <==================
  \bolditem{Caption:} xxx fsdkjnfdskf sdnjdsnfmdns dnsmfndsmfnds 
    nfd Pop"=Operationen nsdmfn msndmnsdbfinsfdn % <====================
  \bolditem{Another caption:} yy
\end{boldenumerate}

\end{document}

you get the wished result:

enter image description here

  • Upvoted as the most comprehensive answer (so it will no longer bumped to the homepage… ;-) , but we should acknowledge the OP’s priority at least for the solution for German, shouldn’t we? – GuM May 12 '18 at 23:58
1

Indeed, many other language definition files for the babel package, beside German, define the same shorthand to insert explicit hyphens between words without affecting TeX’s ability to hyphenate those words. However, it is easy, with the help of Appendix H of The TeXbook, to write a small macro that does the same, without depending on external packages.

Indeed, TeX looks ahead for words to be hyphenated starting from every glue item in a horizontal list, so it suffices to add \nobreak\hskip\z@skip after the explicit hyphen: the \nobreak will prohibit a line break at the following glue, but that glue will “count” as a starting point for the lookahead notwithstanding. Morevover, in order to permit hyphenation of the word that precedes the explicit hyphen, it is necessary, and sufficent, to insert between the word and the hyphen certain types of nodes, the “cheapest” of which is probably an empty \vadjust node. So:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\makeatletter

\newcommand*\+{\vadjust{}-\nobreak\hskip\z@skip}

\makeatother



\begin{document}

\showhyphens{arithmetical-mathematical-geometrical}
\showhyphens{arithmetical\+mathematical\+geometrical}

This book treats of several complex problems that are
arithmetical\+mathematical\+geometrical in nature.  I~don't believe, however,
that such word as the compound adjective
``arithmetical\+mathematical\+geometrical'' exists in English: indeed, I've just
made it up.

\end{document}

Compare the output of the two \showhyphens commands

Underfull \hbox (badness 10000) in paragraph at lines 18--18
[] \T1/cmr/m/n/10 arithmetical-mathematical-geometrical

Underfull \hbox (badness 10000) in paragraph at lines 19--19
[] \T1/cmr/m/n/10 arith-meti-cal-math-e-mat-i-cal-ge-o-met-ri-cal

to check that everything works as expected. You can also have a look at the output produced:

Output of the code

0

I could figure out a workaround: The problem occured for the German word Pop-Operationen for example. Instead of Pop-Operationen I wrote Pop"=Operationen which additionally allows the common hyphenations of both words. In this special case I got

"Pop-Operatio-

nen"

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.