[texhax] Use of \symbol{`\_} versus \symbol{'137} to produce \verb+_+ in moving arguments.

Beuthe, Thomas thomas.beuthe at cnl.ca
Mon Feb 23 21:02:51 CET 2015



Since \verb cannot be used in moving arguments like \chapter and \section

it becomes difficult to produce an exact analog of the underscore character

in a tt font in these situations.


A viable alternative is to use \symbol as an alternative.


A detailed discussion of the pros and cons of using this approach has already

taken place here:




This and other discussion led me to use the \texttt{A\symbol{`\_}B}}

type of solution to produce a "verb-like" texttt output for the underscore

in section headings, since the \verb environment itself cannot be used

in section headings.


This solution produces secondary difficulties however, as hinted to in

above referenced discussion.


For example, I wanted to include the section headings as part of a

footer, but the use of the \leftmark and \rightmark

causes the fancy head and footer package problems due to the

implicit protect in the \symbol, and doing the following

type of thing:




causes an error of the following type:


! Improper alphabetic constant.

<to be read again> 



as a result.


Seems there's an implicit protect in there.

This was also hinted at in the above reference.


There are a number of alternatives that can be used:


  {\tt \string _}  % descend into plain TeX

  {\tt \char`\_} % descend into plain TeX

  {\tt \symbol{'137}} % official LaTeX, Lamport p 116

  {\tt \symbol{`\_}} % not official LaTeX, but it works!


Since last one messes up things for the \rightmark,

I tried the \symbol{'137} symbol alternative, and it seems

to work.


Here are two minimal working examples:


This one does not work:



















and this one works:



















So I seem to have solved my problem, but I would like

to know why. Is the \symbol{'137} form simpler and

therefore works because it is expanded earlier?


If anyone could provide a short explanation,

I think it would be helpful both to me and

everyone else who might contemplate this type

of a solution in the future.





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/texhax/attachments/20150223/525629e8/attachment.html>

More information about the texhax mailing list