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 want to insert formatting text with a single command (I know the text beforehand):

 {\addfontfeature{LetterSpace=20.0}Решение}\

How do I "bind" it to a macro? I tried:

 \def\sol#0 {{\addfontfeature{LetterSpace=20.0}Решение}}
 \let\sol {{\addfontfeature{LetterSpace=20.0}Решение}}

Both give errors. I'm sure I'm missing something trivial.

share|improve this question
add comment

3 Answers 3

up vote 5 down vote accepted

Don't use \def for these kinds of things, just use \newcommand when using LaTeX:

\newcommand*\sol{{\addfontfeature{LetterSpace=20.0}Решение}}

\def and \let are pure TeX commands, it is recommended to use the LaTeX equivalent. In your case the proper way to use \def would be:

\def\sol{{\addfontfeature{LetterSpace=20.0}Решение}}

\let lets you copy a command, for example:

\let\solcopy\sol

Now you could change \sol with \renewcommand.

Also see:

share|improve this answer
add comment

Both your invocations of \def and \let are flawed. For the first, to define a macro with no arguments, you just write \def\sol{...}, without #0: the terms #n don't mean "this macro has this many arguments", but rather, "this is the n'th argument". So with one argument you would use \def\sol#1{...}, with two \def\sol#1#2{...}, and so on. It is also possible to intersperse other stuff between the arguments to create a context for the macro, but that's not relevant here.

For the second, \let defines a macro name to be equal to one other token, not a brace group. So what you wrote,

\let\sol {{\addfontfeature{LetterSpace=20.0}Решение}}

is the same as writing something with the following more obvious intent:

\let\sol {
{\addfontfeature{LetterSpace=20.0}Решение}}

meaning that \sol becomes a left brace and then TeX tries to process the rest, which has an excess right brace (since the other member of its pair just got eaten by \let). And that's your error.

That said, as Silex wrote, it's best to just use \newcommand; \def and \let are too primitive for a high-level document. So:

\newcommand\sol{{\addfontfeature{LetterSpace=20.0}Решение}}

As a side note, you should omit the space you put after \def and \let; although it's harmless here, unnecessary spaces in TeX will lead to problems (see this one).

share|improve this answer
add comment

Oh, I found it:

\newcommand\sol{{\addfontfeature{LetterSpace=20.0}Решение}\par}
share|improve this answer
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.