Text FormattingRedefine an existing command

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Redefine an existing command

Post by ptrcao »

Ok so this is wrong, but you can clearly see what the intention is. Please show me how to do it right:

Code: Select all

\renewcommand{\Latex}{\LaTex \xspace}
Last edited by ptrcao on Mon Feb 21, 2011 6:41 pm, edited 1 time in total.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Redefine an existing command

Post by meho_r »

There is no predefined command \Latex, but \LaTeX. So, maybe what you want is to create a new command. E.g.:

Code: Select all

\documentclass{article}

\usepackage{xspace}

\newcommand{\Latex}{\LaTeX\xspace}

\begin{document}

\Latex and some text.

Some text and \Latex.

\end{document}
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Redefine an existing command

Post by ptrcao »

meho_r wrote:There is no predefined command \Latex, but \LaTeX. So, maybe what you want is to create a new command. E.g.:

Code: Select all

\documentclass{article}

\usepackage{xspace}

\newcommand{\Latex}{\LaTeX\xspace}

\begin{document}

\Latex and some text.

Some text and \Latex.

\end{document}
This is specifically what I really wanted:

Code: Select all

\newcommand{\LaTeX}{\LaTeX \xspace}
Is there no way to redefine and already-defined function?
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
Frits
Posts: 169
Joined: Wed Feb 02, 2011 6:02 pm

Re: Redefine an existing command

Post by Frits »

As it seems, LaTeX doesn't allow you to change the \LaTeX command.
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Redefine an existing command

Post by ptrcao »

Frits wrote:As it seems, LaTeX doesn't allow you to change the \LaTeX command.
Can we overcome this? You're sure there isn't a redefine command I can use?
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
Frits
Posts: 169
Joined: Wed Feb 02, 2011 6:02 pm

Re: Redefine an existing command

Post by Frits »

Not that I'm aware of. The only way I can come up with is the way meho_r described.
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Redefine an existing command

Post by localghost »

To redefine a command it requires \renewcommand correspondingly. But there is no need to redefine especially \LaTeX since a single additional backslash right after does the trick.

Code: Select all

Blank space after \LaTeX\ wanted.
But if you insist on redefining especially the \LaTeX command, try the following.

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\let\oldLaTeX\LaTeX
\renewcommand*{\LaTeX}{\oldLaTeX\space}

\begin{document}
  Blank space after \LaTeX wanted.
\end{document}
Or is \LaTeX here only an example for another command you want to redefine?


Thorsten
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Redefine an existing command

Post by ptrcao »

localghost wrote: \let\oldLaTeX\LaTeX
\renewcommand*{\LaTeX}{\oldLaTeX\space}
It appears to work, but just one question:
In this context, does the asterisk serve any functional purpose, or is it just to draw my attention to this line?
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Redefine an existing command

Post by localghost »

I don't want to bore you with LaTeX internals. I think it's enough for you to know that the starred version is for short commands like this here and the normal version is for long commands that can contain paragraphs.
Post Reply