# Why is Latex giving this odd output?

This is my code.

\documentclass{article}

\begin{document}
The substance used in this experiment is 1,1-diphenyl-2-picryl-hydrazyl (DPPH). This organic compound is a relatively stable free radical which has an unpaired valence electron at one atom of the nitrogen bridge which is the source of the paramagnetism of this compound. In a free nitrogen atom, 6 electrons pair off and contribute no orbital or spin angular momentum. Nor do these electrons as a whole have a net magnetic moment.
\end{document}


And this is the output.

Why is it not properly justified?

If it is standard latex behaviour, then what changes can I do to make it properly aligned (justified)?

• Use package chemformula to deal with the compound name. Aug 8 '15 at 14:10
• LaTeX probably doesn't have rules for hyphenation of chemical compounds names. You always can use a \- at a break point, if you know the rules. Aug 8 '15 at 14:10

There is not much choice:

• There is no place for (DPPH) on the first line.

• If (DPPH) is put on the second line, the inter word spaces are too much for a pleasant result.

In this case, package microtype helps (pdfTeX), because it adds more flexibility by allowing the letters to shrink or stretch a little. This helps to reduce the large inter word spaces in the first line:

\documentclass{article}
\usepackage{microtype}

\begin{document}
The substance used in this experiment is 1,1-diphenyl-2-picryl-hydrazyl
(DPPH). This organic compound is a relatively stable free radical which has
an unpaired valence electron at one atom of the nitrogen bridge which is the
source of the paramagnetism of this compound. In a free nitrogen atom, 6
electrons pair off and contribute no orbital or spin angular momentum. Nor
do these electrons as a whole have a net magnetic moment.
\end{document}


• It solves the problem. Thanks. If I may ask, how did you make the output look like this (background and horizontal lines)? Aug 8 '15 at 14:12
• To be honest, i would prefer if the acronym sticks to the full name, though. Aug 8 '15 at 14:14
• @Johannes_B I would like that too. But it ruins the alignment. Aug 8 '15 at 14:17
• @YogeshYadav This is an edge case where LaTeX can't do any magic. In such cases, you have to slightly rewrite the passage. Aug 8 '15 at 14:29
• @YogeshYadav The output is a transparent PNG-image included in the post as a block quote. Meaning that the yellow background and horizontal lines is only part of the TeX.SX site markup, not the LaTeX output itself.
– sodd
Aug 8 '15 at 14:36

There aren't enough places where Latex can adjust inter-word spacing. In these cases, I either rewrite or change textwidth, if your margin sizes aren't dictated by someone else. I've been using the simplemargins package for ages.

Change \textwidth:

\documentclass{article}

\usepackage{simplemargins}
\setleftmargin{1.75in}
\setrightmargin{1.75in}

\begin{document}
The substance used in this experiment is 1,1-diphenyl-2-picryl-hydrazyl (DPPH). This organic compound is a relatively stable free radical which has an unpaired valence electron at one atom of the nitrogen bridge which is the source of the paramagnetism of this compound. In a free nitrogen atom, 6 electrons pair off and contribute no orbital or spin angular momentum. Nor do these electrons as a whole have a net magnetic moment.

\end{document}


Here's a rewrite:

\documentclass{article}

\begin{document}
In this experiment we used 1,1-diphenyl-2-picryl-hydrazyl (DPPH). This
organic compound is a relatively stable free radical which has an
unpaired valence electron at one atom of the nitrogen bridge which is
the source of the paramagnetism of this compound. In a free nitrogen
atom, 6 electrons pair off and contribute no orbital or spin angular
momentum. Nor do these electrons as a whole have a net magnetic
moment.
\end{document}


• +1 for reminding us all that "rewrite the sentence" is often a lot simpler, better solution that invoking all sorts of macro ninjutsu. Aug 8 '15 at 15:29
• @Brent.Longborough I'm going to borrow the phrase "macro ninjutsu". I love it!
– Ruby
Aug 8 '15 at 17:42
• In real life there are many situations were change the \textwidth is not allowed (journals) or is not a practical option (How many new problems may appear in an already well-formatted long document?). On the other hand, simplemargins is an very old package that is not in TeXlive nor in CTAN, so is by far is more convenient the geometry package. However, also +1 for remind the option of rewriting the text.
– Fran
Aug 9 '15 at 8:51
• @Fran Do you really think I should switch to the geometry package? If so, why? I've been working with simplemargins for ages. My feeling is always, if it ain't broke, don't fix it.
– Ruby
Aug 9 '15 at 16:47
• @DeliaRuby If you are used to do so and it works, there's nothing wrong following this method, but is not the best suggestion to everyone because (a) geometry also works very well, (b) it is installed by default, ready for use, (c) it is also simple to change the size of the margins (in your mwe: \usepackage[margin=1.75in]{geometry} and (b) geometry have many more options, as showframe, showcrops, change the layout in the middle of the document, etc. Run texdoc geometry for more information.
– Fran
Aug 9 '15 at 19:09

If you don't want to rewrite the text, use the sloppypar environment to relax the spacing rules for the paragraph.

\documentclass{article}

\begin{document}
\begin{sloppypar}
The substance used in this experiment is 1,1-diphenyl-2-picryl-hydrazyl (DPPH). This organic compound is a relatively stable free radical which has an unpaired valence electron at one atom of the nitrogen bridge which is the source of the paramagnetism of this compound. In a free nitrogen atom, 6 electrons pair off and contribute no orbital or spin angular momentum. Nor do these electrons as a whole have a net magnetic moment.
\end{sloppypar}
\end{document}


The right answer IMHO for Overfull \hbox ... problems is microtype, but just for the record, specially if you are using xelatex (where the MWE of Heiko Oberdiek do not work), exactly the same ouput for this paragraph is obtained simply with \emergencystretch1em (or \setlength{\emergencystretch}{1em} for the purist):

\documentclass{article}
\emergencystretch1em
\begin{document}
The substance used in this experiment is 1,1-diphenyl-2-picryl-hydrazyl
(DPPH). This organic compound is a relatively stable free radical which has an
unpaired valence electron at one atom of the nitrogen bridge which is the source
of the paramagnetism of this compound. In a free nitrogen atom, 6 electrons
pair off and contribute no orbital or spin angular momentum. Nor do these
electrons as a whole have a net magnetic moment.
\end{document}


Edit

As also seem of interest in some comments to maintain the acronym in the first line, beside of the changes of the text or the layout as proposed Delia Ruby, a general package ninjutsu solution could be microtype with a reasonable settings of the shrink option.

\documentclass{article}
\usepackage[shrink=46]{microtype}
\begin{document}
The substance used in this experiment is 1,1-diphenyl-2-picryl-hydrazyl
(DPPH). This organic compound is a relatively stable free radical which has an
unpaired valence electron at one atom of the nitrogen bridge which is the source
of the paramagnetism of this compound. In a free nitrogen atom, 6 electrons
pair off and contribute no orbital or spin angular momentum. Nor do these
electrons as a whole have a net magnetic moment.
\end{document}


However, the minimum value in this case must be at least 46, that seem a little excessive, so whether this is a good idea just for this MWE ... I leave open.

Anyway, is worth to note that a strong shrinking could be limited just to the problematic paragraph:

\documentclass{article}
\usepackage{microtype}
\SetExpansion[context=bigformula,shrink=60]{encoding=OT1}{}
\begin{document}

Normal text that not need strong shrinking.

{\microtypecontext{expansion=bigformula} The substance used ... }

More text that not need strong shrinking.

\end{document}

• This doesn't help the problem of keeping the acronym next to the name of the compound.
– Ruby
Aug 8 '15 at 23:46
• @DeliaRuby Please see my updated answer, but anyway an Overfull \hbox is a typographic problem, but there are nothing really wrong if the acronym jump to next line, is only matter of personal preferences, that moreover was out of the question.
– Fran
Aug 9 '15 at 8:21