# Allow words containing forwards slashes to be broken over lines at the point where the forward slash occurs

Does anyone know how to use the hyphenat package in pdflatex to create an automatic hyphenation rule whereby forwards slashes may be used to break words over lines, or as hyphenation points? I've read the documentation for the hyphenat package, but I can't seem to find a way to create a global rule.

Ideally, I'd like to be able to allow line breaks for words with forward slashes in, e.g. to change

Lisinopril/Hydrochlorothiazide


to

Lisinopril/
Hydrochlorothiazide


This is just one example of this. I have many drug class combinations like the above in tables in my appendices, and I need some automated way to prevent line overflows.

• you can use \slash instead of / – David Carlisle Apr 3 at 10:38
• The danish babel definitions contains the following  {\bbl@allowhyphens\discretionary{/}{}{/}\bbl@allowhyphens}{}}, this means under danish babel I can use "/ to enable line breaking at a /, you might be able to adapt this to what ever language you are using. (note that under danish babel, " is an active char) – daleif Apr 3 at 10:41

The two approaches are to either make / look like a letter as far as the hyphenation algorithm goes, or else to reset the hyphenation algorithm following a slash.

(1)

A direct steal/modification of my answer here: Add hyphenation pattern for word with special characters

Of course, it helps to define the slashed words hyphenation patterns in advance.

\documentclass{article}
\lccode\/\/

\hyphenation{Lis-in-o-pril-/Hy-dro-chlor-o-thi-a-zide}

\setlength\textwidth{1mm} % just for this example
\begin{document}
. Lisinopril/Hydrochlorothiazide
\end{document}


Without manually specifying the hyphenation pattern in advance, it is still hyphenatable, but just not optimal:

(2)

The other way is to follow the / with \hspace{0pt}, which I codify here as \?:

\documentclass{article}
\newcommand\?{/\hspace{0pt}}
\setlength\textwidth{1mm} % just for this example
\begin{document}
. Lisinopril\?Hydrochlorothiazide
\end{document}


This approach works because the \hspace{0pt} resets the hyphenation algorithm to start looking again for new places to hyphenate.

• Thank you for your reply. Is there any way to make "/" a possible break point without altering all the "/"s to something else in the document. Currently, I'm compiling my pdfs using Sweave in RStudio, and the "/"s all occur in tables I'm reading into my main document in R code chunks, .e.g. – Feakster Apr 3 at 11:10
• @Feakster Approach (1) does that. The key is to use \lccode\/\/ in the preamble, and ideally to specify hyphenation patterns for such words. – Steven B. Segletes Apr 3 at 11:12
• @Feakster I am sorry that I am not a user of R and cannot offer assistence on that end. – Steven B. Segletes Apr 3 at 11:14
• Sorry, I'm struggling to format my code for the comments boxes. – Feakster Apr 3 at 11:18
• @Feakster Rather than a comment, it might be better to edit your question, showing this extra code in a supplement to the original question. – Steven B. Segletes Apr 3 at 11:19