I am describing an algorithm in a journal paper. In this algorithm I have a few variables. I gave them the same names as in my source code (C++ source of the algorithm, not LaTeX source). So I have variables such as:

  • new (new node that is being inserted)
  • reference (arbitrarily chosen node)
  • x (generic looping variable)

In computer programming it is good practice to give variables meaningful names. However when reading other articles describing algorithms I often see abbreviated names. In my case it would be:

  • n
  • r
  • x

Is this a good practice? Is there a difference between programming and mathematical texts?

Another thing is the mode in which to write these variables in text and in an algorithm environment. Should I use:

  • $new$
  • \emph{new}
  • \textbf{new}
  • \textit{new}

Or perhaps use one convention in inline text and a different one in equations and algorithm environments?

I couldn't find any relevant information in the editor's manual for the journal and also nothing relevant in the LaTeX class manual. All they say is to make variables italic, so that they are not confused with units (for example W can be confused with Watt).

  • 3
    I would consider defining a new command, so that later on, you can easily change the formatting. If you choose the $new$ approach, please consider $\mathrm{new}$, for this provides better spacing/kerning. Indeed, $new$ would suggest the mathematical multiplication of $n$, $e$, and $w$. Besides that, I do not have a clear suggestion for a particular kind of formatting. Defining your own command will make it modular though.
    – jmc
    Nov 25 '13 at 15:52
  • 2
    never $new$ the math italic font is designed to make adjacent letters not look like a word, but rather an implied product of three variables (as in math rather than computer science variables are almost always one letter:-) If you need both math and text usage use $\mathbf{new}$ or $\mathit{new}$ as you choose, then in a larger math context you can simply use \mathbf{new} or \mathit{new} and get the same font. Nov 25 '13 at 15:57

You have asked two separate (interesting) questions.

The first is about names. In general, mathematicians prefer generic names ("n", "r", x") while programmers prefer longer, more meaningful ones. In your case I'd go for meaningful.

Your second question is about typography. There I think the computer programmer's practice of delayed commitment will serve you well. Write a macro

...  convention for typesetting #1 ...

and use \variable{new} in your document. Then you can change the formatting later to whatever you (or your editor) likes. See the comments above for some typographical do's and don't's.

You could even postpone committing to variable names with macros like


one for each variable name. If there were lots of those you could have a macro to generate the macros from a list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.