19

I use LaTeX to take quick notes about my programming work. I have a couple of frustrations:

  • I need to use underscore a lot because of variables named with underscores. However, I have to escape each one of them "\_", thus making my notes less readable on the markup side.
  • I commonly want to use "<" and ">" symbols - why oh why are the default representations of these symbols "¿" and "¡"?

Is there anyway I can alter LaTeX so that "_", "<", and ">" literally typeset as "_", "<", and ">"?

28

There are canonical ways to fix both of these problems. For the underscore:

\usepackage{underscore}

For the rendering of < and >:

\usepackage[T1]{fontenc}
\usepackage{lmodern}
11

FWIW, since the last month \nonknuthmode is default in ConTeXt. What this means is _, ^, and & work in text mode. So, the following is a valid input:

\starttext
under_score car^et & ampersand work in text mode, and have their 
usual meaning in math mode
\startformula
  x_a^b = \cases{ 0 & a < b \cr 1 & a \ge b }
\stopformula
\stoptext
  • 7
    Interesting - this is more-or-less the long-term LaTEX3 plan too. I'll probably take a look at the appropriate ConTeXt code at some stage. – Joseph Wright Feb 19 '11 at 6:01
8

An obligatory ConTeXt answer (plus Aditya's :)), using \asciimode will make all special characters "un-special" except \, { and }:

\starttext
\asciimode
$ % & _ # ^ ~ | < >
\{ \} \backslash
\stoptext
3

Building on (I do that a lot, lately) Roflcoptr suggestion of using \textgreater and \textless, you can do

\catcode`\<\active
\catcode`\>\active
\let<\textgreater
\let>\textless
\catcode`\_\active
\let_\_

I am assuming that you are not using _ in maths as well. Otherwise, try

\begingroup
\lccode`\~`\_
\lowercase{\endgroup
  \def~{\ifmmode\expandafter_\else\expandafter\_\fi}}
\catcode`\_\active

instead of \catcode... \let_\_. EDIT: note the different placement of \catcode....

  • Using \mathcode"8000 (=‘math active’) is a more robust way to do this sort of thing. (See the internals of underscore.sty.) Although I'm not aware of any specific problems with the approach you've taken (perhaps it's less efficient, is all?). – Will Robertson Feb 8 '11 at 5:51
  • 1
    This will probably have the same problem as underscore, where \includegraphics{filename_with_underscore} won't work. – Evgeni Sergeev Aug 1 '13 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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