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.

This code

\documentclass{article}
\usepackage{fouriernc}

\begin{document}
$a_1$

$a_{\!1}$
\end{document}

produces this output:

Spacing

I like the spacing on the lower one much more.

Is there a way to automatically use \! on all subscripts so that I don't have to type it everytime? If this is not the optimal way to achieve this spacing, I'm eager to learn a better way, of course.

share|improve this question

1 Answer 1

up vote 11 down vote accepted

You can redefine the command _. Therefor you must change the catcode of the sign. The redefinition in the example should be done in the preamble. I did it in the document body to demonstrate the behaviour.

\documentclass{article}
\usepackage{fouriernc}

\begin{document}
$a_1$

$a_{\!1}$

 \catcode`\_\active
 \def_#1{\sb{\!#1}}

$a_{1}$
\end{document}

enter image description here


Instead of changing the underscore global, you can set the mathcode of the token to redefine (suggest by David Carlisle and improved by egreg):

\documentclass{article}
\usepackage{fouriernc}

\begin{document}
$a_1$

$a_{\!1}$

\catcode`\_=12
\mathcode`\_="8000
\begingroup\lccode`\~=`\_
\lowercase{\endgroup\def~#1}{\sb{\!#1}}

$a_{1}$
\begin{equation}
1+1=1\label{eq_1}
\end{equation}
Text \ref{eq_1} Text$_1$
\end{document}

However the best is to avoid _ in labels.

share|improve this answer
    
Thanks, but this produces errors when I use underscores in \label{}. How can I fix this? –  Foo Bar Apr 18 '13 at 9:05
    
@FooBar What exact errors you get? You might try to put the nasty code in the preamble so that the catcode is already \active at \begin{document} when the .aux file is read. –  tohecz Apr 18 '13 at 15:23
    
@tohecz It is in the preamble and I get Missing \endcsname inserted in the .aux file on lines like \usedref{eq:label_with_underscore}. –  Foo Bar Apr 18 '13 at 15:29
    
This does not work at all. Your new code does not change the spacing but also does not give any warning or error. –  Foo Bar Apr 18 '13 at 16:05
    
Thanks, this works now. :) –  Foo Bar Apr 18 '13 at 16:23

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.