3

I have words in my text that contains underscores and that exceeds the boundaries of the page

enter image description here

the word is typed in the text as

FOS\_SOCIAL\_SCIENCE

I want the word to be able to hyphenate at the underscore boundaries.

I have tried:

\hyphenation{FOS-\_-NA-TU-RAL-\_-SCIEN-CE}

but pdfLatex return the following error

Improper \hyphenation will be flushed. \hyphenation{FOS-_

I don't want to use the underscore package due to incompatibilities

I also tried

\renewcommand{\_}{%
    \textunderscore\nobreak\hspace{0pt}%
}

which doesn't work: compile without errors but the word is not hyphenated

I also tried:

\def\_{\_\allowbreak\hspace{0pt}}

which does not compile. The error message is:

TeX capacity exceeded, sorry [input stack size=5000]. \item[FOS_NATURAL_SCIENCE]

9

Why do you use \nobreak if you want something to break? Without it it works as expected:

\documentclass{article}

\textwidth=1mm
\begin{document}
FOS\_SOCIAL\_SCIENCE   

\renewcommand{\_}{%
    \textunderscore\nobreak\hspace{0pt}%
}

FOS\_SOCIAL\_SCIENCE

\renewcommand{\_}{%
    \textunderscore\hspace{0pt}%
}

FOS\_SOCIAL\_SCIENCE

\end{document}

enter image description here

  • It doesn't wotk with without the nobreak option. I think it is unable to break in points other than the underscore, don't know why. I have \documentclass[12pt, a4paper, draft]{scrbook} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} as the first lines of the preamble – raffamaiden Dec 1 '17 at 9:10
  • 1
    It works in my example as you can see in the picture. If it doesn't work for you you will have to make a complete example. – Ulrike Fischer Dec 1 '17 at 9:12
  • The problem was only with $\text{FOS\_NATURAL\_SCIENCE}$. Removing the math environment and defining _ as you did solved the problem – raffamaiden Dec 1 '17 at 9:20

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.