In technical documentation, sometimes the tool's automatic hyphenation makes a bad break in the middle of a term, like the name of an environment variable or function. In these cases I would rather have a short line than hyphenation, though I want hyphenation in the document in general. I can try to "write around" egregious cases to try to avoid the problem term being near the end of a line, but that's fragile. I'm looking for a solution that fixes all of them, without me having to individually handle each case.
I am using DocBook, which we transform to Formatting Objects (FO) and thence to PDF. Ideally I would like to be able to write a style directive that says "don't hyphenate inside these XML elements" and apply it to <classname>, <methodname>, and several others. This FO documentation describes a way to do this at the page-block level, e.g. to turn off hyphenation in a table of contents or a preface, but that's too coarse. This forum post suggests a way to hard-wire them within the text, meaning I would have to put a special directive around each class name, method name, and so on. (Also, it sounds like it didn't work for him.)
How can I most easily prevent bad hyphenation breaks in my code elements, working within the tool chain I have? (I'm not free to change that.)