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 would like to know if renaming a command is possible in LaTeX. For instance, could I change the \section by \sec ?

I read that some people used something called "alias".

share|improve this question
2  
\let\sec\section and then use \sec. That way you don't loose \section you just copy its definition to \sec. –  Manuel Jul 26 at 15:00
    
Thanks !en.wikibooks.org/wiki/TeX/let –  TexisHard Jul 26 at 15:01
3  
The most natural way is \newcommand{\sec}{\section}. But the best way is not doing it. Using an alias for a command might confuse your editor (code folding features, for instance). –  egreg Jul 26 at 17:04

1 Answer 1

There are a number of ways, depending on what you're after:

enter image description here

\documentclass{article}
\setlength{\parindent}{0pt}% Just for this example
\begin{document}
\let\TextBF\textbf% Copy definition of \textbf into \TextBF

\textbf{textbf}\par
\TextBF{TextBF}

\let\textbf\texttt% Change original \textbf to now be equivalent to \texttt

\textbf{textbf}\par
\TextBF{TextBF}% \TextBF remains unchanged

\hrulefill

\newcommand{\TextIT}{\textit}% \TextIT will be replaced with \textit

\textit{textit}\par
\TextIT{TextIT}

\let\textit\texttt% Change original \textit to now be equivalent to \texttt

\textit{textit}\par
\TextIT{TextIT}% \TextIT changes with \textit

\end{document}
  • \let<csnameA><csnameB> makes a copy of the definition of <csnameB> and places it into <csnameA> (like a regular copy-and-paste). It has the advantage that you can now redefine <csnameB> without affecting the copy you just made (<csnameA>).

  • \newcommand{<csnameA>}{<csnameB>} merely points <csnameA> to <csnameB>. To that end, updates to <csnameB> will still be reflected in <csnameA>.

Related questions:

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.