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 type my latex document with gedit.
I use a lot of macro to facilitates typesettings.
I put all of them just after the begin{document} tag.
For a homework question says, I use at least 20 macros.
For example, in a question involving sequence

\newcommand{\xn}{x_n}
\newcommand{\yn}{y_n}
\newcommand{\xns}{\left\{ \xn \right\}}
\newcommand{\yns}{\left\{ \yn \right\}}

The problem is I never remember which one I created before.
Also, it's distracting, when writing a sentence, to always go back to the top of the document to create the macro I need.
It breaks my thinking follows.

I was wondering, what people do to facilitate that.
In an Eclipse IDE world, when writting code, I can use a function without defining it, then ask Eclipse to generate the body of the function.
Is there some kind of program which helps to manage \newcommand?

The answer doesn't have to be limited to gedit.

I know I can externalize macros in a command.tex file say.
I do this for general purpose macros, like probability notation, parenthesing,...
It is really macros specific to a question which are hard to manage.
It's not practical to define a general set of macro command_homework.tex.
The macros must be created on a question by question basis.
For example, in a question on sequence \xn is x_n, while for a question on limit it is \frac{x}{n}.

share|improve this question
2  
@marczellm texstudio does so. It shows every command defined by \newcommand (I would guess in the actual document or project) in its autocompletion menu automatically. –  Benedikt Bauer Feb 3 '13 at 16:43
4  
But isn't it conterproductive having so many new defined commands that you cannot remember which you defined and how? Above that it will make the code quite unreadable especially if you define the same completely different depending on context... –  Benedikt Bauer Feb 3 '13 at 16:47
7  
Maybe this is not your real question, but I think it worthwhile to expend a few extra keystrokes and keep your code readable. In fact you save no keystrokes using \xn instead of x_n, and for that you gain ambiguity. Use a keystroke text expander like AutoHotKey or TextExpander to generate template code and fill-in the parameters. Save macros for cases of major semantic or presentation markup. –  Matthew Leingang Feb 3 '13 at 17:05
3  
@NicolasEssis-Breton You seem to contradict yourself: if you know what \xn means, then you don't have to look for it in the preamble. If you find yourself not remembering whether you have defined a shortcut or not, then you're probably overusing these shortcuts. To me \axnzn is by far less clear than \lvert x_{n} - z_{n}\rvert –  egreg Feb 3 '13 at 17:30
3  
As @MatthewLeingang said, macros are best used for semantic markup, such as \newcommand{\set}[1]{\left\{#1\right\}}. This helps another reader (or yourself at a later time) to understand the code faster. Shortcuts like \aznyn may give you a small speedup when writing, however they decrease readability, and as you described, even you keep forgetting which ones you have yet to define, so overall it's not very effective. Your point may be valid though, if you have to write the same formulas like 6-8 times and the document is not for long-term preservation or collaborative work. –  marczellm Feb 3 '13 at 17:56
show 5 more comments

1 Answer

up vote 3 down vote accepted

This may not be the answer you're looking for, which is why I made it first as a comment.

I think it worthwhile to expend a few extra keystrokes and keep your code readable. In fact you save no keystrokes typing \xn instead of x_n, and for that you gain ambiguity that comes from having to remember how (or whether) you defined the macro.

Use a keystroke text expander like AutoHotKey (Windows) or TextExpander (Mac) to generate template code and fill-in the parameters. Some IDEs (like TeXShop, and vi/emacs) have key combinations to do this too. Save macros for cases of major semantic or presentation markup.

share|improve this answer
1  
With time, your initial comment sank in me, and I now reserved macro for case of major semantic. Thank you, and also the other members, for teaching me the right path. –  Nicolas Essis-Breton Aug 16 '13 at 22:07
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.