[SOLVED] Re: About \newcommand

Darío darioslc at protonmail.com
Tue Aug 10 01:15:44 CEST 2021


> On Mon, 9 Aug 2021 at 23:46, Christopher Skeels
> Chris.Skeels at unimelb.edu.au wrote:
>
> > I suspect that more flexibility can be gained using the xspace package and the associated xspace command in your \newcommand definition:
>
> perhaps, but see
> https://tex.stackexchange.com/a/86620/1090
>
> David
>
> > \usepackage{xspace}
> > \newcommand{\gnr}{\emph{género}\xspace}
> > On 10/8/21, 8:19 am, "texhax on behalf of Rolf Turner" <texhax-bounces+chris.skeels=unimelb.edu.au at tug.org on behalf of r.turner at auckland.ac.nz> wrote:
> >
> >     On Mon, 09 Aug 2021 21:45:36 +0000
> >     Darío via texhax <texhax at tug.org> wrote:
> >
> >     > Hello! I have written an article, and habitually I use \\newcommand
> >     > for some words commonly write and with emphasis. For example
> >     > \\newcommand{\\gnr}{\\emph{género}}, but the problem is when I call the
> >     > command and then compile because in the pdf the word género appears
> >     > together to the next word, ie: (in .tex file) Pl \\gnr puede definirse
> >     > .... (in .pdf file compiled) El géneropuede definirse .... (can not
> >     > show emphatic word género) Also occur without emphatic or without
> >     > LaTeX command. As you can see, appears together with the words género
> >     > and puede, how can you do it to separate the words? Not works fine if
> >     > I define \\newcommand{\\gnr}{\\emph{género }}, ie with a space final
> >     > because may occur that I write a comma or dot.
> >     >
> >     > Thanks a lot, regards!
> >
> >     If I understand you correctly (always a dubious assumption in my case!
> >     :-)) all you need to do is put "\\ " after the "\\gnr".  (That's
> >     "backslash space"):
> >
> >        \\gnr\\ puede definirse
> >
> >     TeX/LaTex ignores spaces after a command name.  See [1], p. 53.
> >
> >     cheers,
> >
> >     Rolf Turner
> >
> >     [1] Leslie Lamport.  LaTeX --- A Document Preparation System;
> >     User's Guide and Reference Manual, second edition, Addison-Wesley,
> >     Boston, 1994.
> >
> >     --
> >     Honorary Research Fellow
> >     Department of Statistics
> >     University of Auckland
> >     Phone: +64-9-373-7599 ext. 88276
> >

Thanks a lot for your help!
Both methods work fine, but it is really more flexible using the package xspace because is not necessary to write always {\gnr} or \gnr\ (any letter), and only adds \xspace after the command. Also, this package respect the dot or comma or similar ie does not add a space then of this.

Thank you newly!
Darío




More information about the texhax mailing list.