17

what do you see as best way of presenting class names in LaTeX documents (writing about a piece of software).

I'm currently using \texttt (monospaced typewrite font) which otherwise works fine but my class names end up goind "over" the margins.

So, I'm asking for either

  • an alternative (good-looking) way of representing the class names
  • way to make sure my classnames won't go over the margins

br, Touko

Touko
  • 11,359
  • 16
  • 75
  • 105

3 Answers3

19

\texttt is a good choice.

If your class names end up "going over the margins", that's because LaTeX doesn't hyphenate \texttt text by default. (You're probably getting warnings about "overfull hboxes" because of this.)

There are two possible solutions to this: Either rewrite your text so that class names don't appear at the ends of lines, or tell LaTeX to hyphenate your class names (if that's acceptable to you). For the latter, check out the hyphenat package. Try using it like this:

\usepackage[htt]{hyphenat}

You will also probably need to tell LaTeX where to hyphenate your class names, like this:

This\-Is\-My\-Long\-Class\-Name

(for class ThisIsMyLongClassName).

Martin B
  • 23,670
  • 6
  • 53
  • 72
  • 2
    Thanks. To get the "over-margin-going" class names to go to next line with hyphenat, \sloppy seems to work fine. When found this hyphenation, more info was found in http://www.tex.ac.uk/cgi-bin/texfaq2html?label=hyphoff – Touko Aug 25 '09 at 10:39
13

Perhaps better would be to define your own macro:

\newcommand{\classname}[1]{\texttt{#1}}

which you then use like this:

\classname{MyClass}

Doing this means that your class names are tagged as such, not as typewriter-style text.

user229044
  • 232,980
  • 40
  • 330
  • 338
High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
4

You could use the url package, which despite its name can be used to typeset any kind of text in a typewriter font, allowing for linebreaks.

Jouni K. Seppänen
  • 43,139
  • 5
  • 71
  • 100
  • well, \url{} has plenty of built-in logic dedicated to typesetting... urls ! trying to abuse just it to typeset random stuff in a typewriter font can seem appealing a first but might very well bite you later – Gyom Oct 12 '11 at 12:18
  • @Gyom I said "the url package", not "the \url command". The package documentation says "[it] is intended for email addresses, hypertext links, directories/paths, etc., which normally have no spaces. [...] [N]ew url-like commands may be defined using \cs{urldef}." – Jouni K. Seppänen Oct 14 '11 at 15:27