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 am working on a document that has a lot of subscripts. I am getting really tired typing the _. Is there a way to do the following:

Everytime I want $v_1$, I just want to type in v1. Or b1 produces b_1 or c1 produces c_1.

Bonus points for someone who can teach me how to do something like b{1 and 2} for b_{1 and 2} or something even more robust where I can specify whether its a superscript or a subscript.

I understand this might end up in more keystrokes but I'd rather have simple keystrokes than moving my hand across the keyboard for the underscore.

I also realized I don't use the number pad. Is there a way to hotkey the number pad so that press "1" on the number pad will insert \textbf{} for me or something similar -- this might be posted as another question

share|improve this question
2  
see recent questions for reasons why it's a bad idea to do this, and possible solutions if you wish to do it anyway Expanding subscript and subscript capabilities and alternative syntax of subscripts using tex –  David Carlisle Jan 31 '13 at 22:54
    
Regarding your question about "hotkeys", this is a feature of your editor, not of TeX/LaTeX, and as such it is off-topic on this site. Regarding your main question, I am not sure what you want: is it that any digit following a letter should be subscripted? –  Bruno Le Floch Jan 31 '13 at 22:55
    
@BrunoLeFloch Yes. Any series of numbers should be subscripted. b2343 means b_2343 –  masfenix Jan 31 '13 at 23:39
2  
If zou might the difficultz of tzping _ then zou could trz a different kezboard lazout. The German lazout has the _ kez just left the shift kez, making it easilz accessible. But, there are drawbacks: the y and z kez are exchanged for example... –  Martin Scharrer Jan 31 '13 at 23:39
    
I see. I believe you might be using a different layout where your z is switched with y :) –  masfenix Jan 31 '13 at 23:41
add comment

1 Answer

This is implemented in mhchem package: \ce{H20} produces an equivalent to $\mathrm{H}_2\mathrm{O}$. You may want to either use this package directly or look into its code to borrow ideas.

share|improve this answer
    
I think the OP asks for a way without the \ce{} macro letting TeX parse the scripts. –  percusse Jan 31 '13 at 23:29
    
Yes, and this is why I recommended looking into the code to implement a similar environment or global switch. –  Boris Jan 31 '13 at 23:31
    
Chemical formulas are very specialized and one can assume that every number (after a letter) in them is a subscript; what about $b1+1$? And b23 should mean b_{2}^{3}, b_{23}, b^{23} or b^{2}_{3}? –  egreg Jan 31 '13 at 23:34
    
b23 should mean b_{23}. I am not worried about superscripts, but if there IS a way to do it (i cant see a way) then I would appreciate that knowledge also –  masfenix Jan 31 '13 at 23:38
    
Well, Martin Hensel put some nice heuristics in the package: \ce{b1+c} means $b_1^+ c$, while \ce{b1 + c} means $b_1 + c$, \ce{b23} means $b_{23}$ etc. You always can use explicit _ and ^ with grouping to override, but defaults work fine in 90% of cases and turn out to be very useful when you quickly type, e.g. making notes during a talk. I agree that outside of chemistry a different set of defaults should be designed. –  Boris Jan 31 '13 at 23:40
show 1 more 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.