1

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

masfenix
  • 1,429

1 Answers1

2

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.

Boris
  • 38,129
  • 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
  • I believe that should be sufficient for my needs. Thanks. – masfenix Jan 31 '13 at 23:42