(I'm new to TeX and LaTeX) I would like to create math expressions with multi-letter variable names as used in programming languages. For example, in
a^2 + efg^2
I would like "efg" to be treated like a single variable, just like "a".
Can anyone help? Is there something I should read concerning this?
Math & Science ⇒ Programming Language Variables
NEW: TikZ book now 40% off at Amazon.com for a short time.

Re: Programming Language Variables
Please be more specific, I can't help you right now since I don't understand the question.
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
Follow howtoTeX on twitter
- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
Programming Language Variables
In math mode, letters are treated like variables, that's why the spacing in math is different from spacing in text, as you noticed. You could use \mathit for example, or \mathrm for upright symbols (like for operators).
I recommend writing a macro for your variables, so you can easily change the appearance in the complete text by modifying the macro.
Now, even if you define a lot of variables, one single macro is responsible for the appearance in text, so you can still fine tune if required.
Stefan
I recommend writing a macro for your variables, so you can easily change the appearance in the complete text by modifying the macro.
Code: Select all
\documentclass{article}
\newcommand*{\var}[1]{\mathord{\mathit{#1}}}
\newcommand*{\efg}{\var{efg}}
\begin{document}
Compare $efg^2$ versus $\efg^2$
\end{document}
Stefan
LaTeX.org admin
Re: Programming Language Variables
I figured that efg was being treated like 3 variables; or perhaps that the f was being treated like the symbol for "function". I also ran across \mathrm, \mathit, and so forth.
The main thing, though, was to find a way to define a multi-letter variable. So thank you for the macro. That gives me an immediate solution, and an area to delve into for more ideas. Also, thanks for the hint about formatting variables differently.
The main thing, though, was to find a way to define a multi-letter variable. So thank you for the macro. That gives me an immediate solution, and an area to delve into for more ideas. Also, thanks for the hint about formatting variables differently.