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'm new to LaTeX and I guess I'm still a little confused about the difference between TeX and LaTeX. Under what circumstances would you actually need to define new TeX macros within a LaTeX document? What's the difference between \def and \newcommand (other than the fact that one is TeX and the other is LaTeX)? Can someone give me an example?

share|improve this question
    
Perhaps take a look at tex.stackexchange.com/questions/6776/what-are-tex-and-latex –  Joseph Wright Sep 4 '11 at 14:37
    
Thanks for the link! –  Alex Lockwood Aug 8 '12 at 20:34

2 Answers 2

up vote 9 down vote accepted

LaTeX is based on TeX, see:

You can use TeX within LaTeX documents, however it's recommended to use LaTeX if possible because

  • LaTeX is a higher abstraction level
  • LaTeX does more error checks
  • Using LaTeX commands in LaTeX commands is simply more consistent, because TeX command don't have to know the LaTeX context they are used within, while LaTeX commands may do

Here's a helpful list regarding LaTeX commands vs. TeX commands:

LaTeX's \newcommand checks if a macro name already exists, so you cannot accidentally overwrite an existing macro with the same name. However, you can still use \def, as said above, for example if you would like to overcome \newcommand syntax restrictions. See:

There's a lot of LaTeX documentation explaining \newcommand and examples. However, you can find a lot of examples using this site's search feature, such as

share|improve this answer

The difference between TeX is not analogous to the difference between, say, C and C++, where it is actually an issue to directly include C code in a C++ program. It's more like the difference between a simple HTML text box like the one I'm using and a fancy text editor like Emacs. (I admit that the analogy between a typesetting engine and a text editor is not that inspired.) Sure, you can use an Emacs window as a text box, but it has a ton of features that make entering and editing text faster and easier, and an infinite capacity to extend them. Of course, in the middle of your hyper-adept Meta-Super-whatever editing session you choose just to type a few lines, it will not break the program. It may even be faster or easier.

Thus it is with TeX and LaTeX. Unlike C++, LaTeX does not replace TeX, but rather, it replaces TeX idioms. The language would still work the same way if you tried to use it, but you have the option (strongly encouraged) to use it differently. In particular, \def and \newcommand both define the same kind of "command": a TeX macro. It's just that \newcommand is smarter about it, while \def is more flexible (and thus more dangerous).

Like with Emacs versus text boxes, most of the time you are doing things that don't depend on TeX vs LaTeX at all: entering plain text is the same in both. Also, I have lied in that it is possible for some TeX commands (even primitive commands like \def, or in practice, \atop) to be redefined to give errors in LaTeX. Also note that I am not going to tell you what commands are actually in TeX (as compared to LaTeX) since LaTeX is designed in such a way that you shouldn't even need to know.

I should say that I have never used Emacs.

share|improve this answer

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.