Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What is the best practice for hyphenating long identifiers like Character.isJavaIdentifierStart when they appear in body text? I am aware of the path package that also deals with otherwise active characters.

On occasion I have locally defined

\def\+{\discretionary{}{}{}}

which introduces a hyphenation point at \+ but no hyphen in order to avoid the confusion whether the hyphen belongs to the identifier or not.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

I am not too sure if there is a best practice, but here are two approaches.

The first method uses the url command to automatically hyphenate at certain points such as for example dots. The second one uses a discretionary (with or without a hyphen). Whatever you choose, I am sure that you will need to give TeX a helping hand, that is you cannot avoid doing some manual editing in the end.

In the example I colored the word and used a libertine family font.

\documentclass{report}
\usepackage{geometry,xcolor,url}
\usepackage{libertine}
\geometry{paperwidth=130mm, paperheight=60mm,
textwidth=95mm, textheight=50mm}

\def\+{\discretionary{}{-}{}}
\def\textinline#1{{\usefont{T1}{fxb}{m}{n}\selectfont\textcolor{purple}{\url{#1}}}}

\def\ttextinline#1{{\usefont{T1}{fxb}{m}{n}\selectfont\textcolor{purple}{#1}}}
\begin{document}
Java programmers tend like to use very long variable names as compared to other
languages. A string such as \textinline{this.class.VariableName}
will get split rather than produce an overfull box?

Java programmers tend like to use very long variable names as compared to other
languages. A string such as \ttextinline{this.classVari\+ableName}
will get split rather than produce an overfull box?
\end{document}

enter image description here

share|improve this answer
1  
I think \discretionary{}{-}{} is clever! It puts the hyphen at the beginning of the next line. –  Christian Lindig Apr 16 '11 at 16:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.