1

I was wondering if it was possible to use a variable within the document to quickly change a string. For example in my cover letter I want to insert the name of a different company but without changing the name manually.

So far I have used the command

\newcommand{\companyname}{Google }

Hi \companyname I want to .... By \companyname, see you.

This method however causes problems with the text. It does not respect the space between the words that follow the command.

Result:

Hi GoogleI want to .... By Google, see you.

I thought about adding a space to the command but if I did this it would cause an extra space to the punctuation which does not suffer this effect.

HABLOH
  • 123
  • See the Arnold Schwarzenegger question: https://tex.stackexchange.com/q/31091/134574. Use Hi \companyname{} I want to or Hi \companyname\ I want to – Phelype Oleinik Feb 18 '22 at 18:47
  • 3
    Heve a look at xspace and write \newcommand{\companyname}{NoGoogle\xspace} – Denis Feb 18 '22 at 19:00

1 Answers1

1

You can define the \companyname with a separator. For example:

\def\companyname/{Google}

Hi \companyname/ I want to .... By \companyname/, see you.

If you forget the declared separator, for example By \companyname, see you then the error

Use of \companyname doesn't match its definition.

is printed.

wipet
  • 74,238