0

How can I justify text like this by for example automatic hyphenation? (which does not affect the rest of the text? If I use \linebreak it will go to the next line but not justify the prior text.

I want each line to be stretched over the full width. I don't mind hyphenation, as long as it is specific and does not affect the rest of my document where I dont want hyphenation.

enter image description here

EDIT:

% !TEX TS-program = pdflatex

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm]{geometry}
\usepackage{titlesec}

\usepackage{lipsum}                 %example text

%justify without hyphen
\tolerance=1
\emergencystretch=\maxdimen
\hyphenpenalty=10000    
\hbadness=10000
\frenchspacing

%include additional layer called paragraph
\titleformat{\paragraph}{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\begin{document}
\paragraph*{((2R,3R,4S,5R,6R)-3,4,5-tris(benzyloxy)-6-(((2R,3R,4S,5R,6R)-3,4,5-tris(benzyloxy)-6-((benzyloxy)methyl)tetrahydro-2H-pyran-2-yl)oxy)tetrahydro-2H-pyran-2-yl)methanol ((OBn)$ _7$-6-TreOH)}

\lipsum[1]

\end{document}
5
  • Welcome to TeX.SE. Please show the underlying code that gives rise to the screenshot you posted. Please also tell us which document class you employ.
    – Mico
    Feb 6, 2022 at 18:29
  • \linebreak will still justify text (perhaps you are thinking oif \newline which would leave the line short, but without seeing an example of your input it is impossible to suggest anything, a lot will depend on how you are encoding the chemical names. Feb 6, 2022 at 18:32
  • @DavidCarlisle I added an example, I have tried \newline and \linebreak but it does not work. It is also difficult to guess for each word where to add it, as this problem occurs often
    – lay lay
    Feb 6, 2022 at 18:40
  • oh the whole thing is a section heading? that makes it harder, no one would hav eguessed that from the original version of the question. But your code is explicitly preventing hyphenation and your question asks if hyphenation is possible, so it isn't clear which you want? Feb 6, 2022 at 18:45
  • @DavidCarlisle I don't want hyphenation, but I do not mind if that is the solution here, as long as it is only confined to this part of the text and not somewhere else
    – lay lay
    Feb 6, 2022 at 18:47

1 Answer 1

2

You can insert a breakpint after each letter (use \ to preserve space and {...} to protect math or other constructs.

enter image description here

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm]{geometry}
\usepackage{titlesec}

\usepackage{lipsum}                 %example text

%justify without hyphen
\tolerance=1
\emergencystretch=\maxdimen
\hyphenpenalty=10000    
\hbadness=10000
\frenchspacing

%include additional layer called paragraph
\titleformat{\paragraph}{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\def\zz#1{\zzz#1{}}
\def\zzz#1{\def\tmp{#1}\ifx\tmp\empty\else#1\linebreak[0]\expandafter\zzz\fi}
\begin{document}
\paragraph*{\zz{((2R,3R,4S,5R,6R)-3,4,5-tris(benzyloxy)-6-(((2R,3R,4S,5R,6R)-3,4,5-tris(benzyloxy)-6-((benzyloxy)methyl)tetrahydro-2H-pyran-2-yl)oxy)tetrahydro-2H-pyran-2-yl)methanol\ ((OBn){$_7$}-6-TreOH)}}

\lipsum[1]

\end{document}
1
  • Oh wow, that's exactly what I was looking for! Thank you so much :)
    – lay lay
    Feb 6, 2022 at 19:01

You must log in to answer this question.

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