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.

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 ">"?

share|improve this question
1  
For your second question, see tex.stackexchange.com/questions/10300/include-and-symbol/… –  Caramdir Feb 7 '11 at 23:49
add comment

4 Answers

up vote 25 down vote accepted

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}
share|improve this answer
    
wow - that was simple –  John Berryman Feb 8 '11 at 4:02
add comment

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

\starttext
\asciimode
$ % & _ # ^ ~ | < >
\{ \} \backslash
\stoptext
share|improve this answer
add comment

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
share|improve this answer
4  
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
add comment

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....

share|improve this answer
    
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
    
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
add comment

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.