Adding a "global" command is possible. But one of the strengths of the TeX system is portability: if you have the same TeX distribution on two machines, the same file will compile on both, with the same result.
What would happen in your case is that compiling the document on a different machine would bang out with an
! Undefined control sequence
error.
The safest way is to have a file, say sigur.sty
containing the lines
\ProvidesPackage{sigur}[2012/01/10 Local macros by Sigur]
\RequirePackage{color}
\newcommand{\alert}[1]{\textcolor{red}{#1}}
with possibly other definition you deem useful, and save it in the "local tree", that is as
/usr/local/texlive/texmf-local/tex/latex/sigur/sigur.sty
and doing
sudo mktexlsr
after that operation.
Any user on your machine will be able to say
\usepackage{sigur}
in their document. Don't forget to enclose the file when you distribute a document using it.
Also, don't forget to document your macros.
I think it might be easier to instead redefine the quote
environment to take an optional argument, so that it could be used as
\begin{quote}
...
\end{quote}
or
\begin{quote}[Title goes here]
...
\end{quote}
So, in the code below, that's exactly what I've done, using
\let\oldquote\quote
\let\oldendquote\endquote
and then, borrowing the 'empty' test from What is the difference between \empty and \@empty? to redefine the quote
environment as
\renewenvironment{quote}[1][]{\oldquote%
\if\relax\detokenize{#1}\relax
``
\else
\begin{center}%
``{\bfseries\itshape #1}%
\end{center}\nobreak
\fi}{''\oldendquote}
Here's the complete MWE
\documentclass{article}
\let\oldquote\quote
\let\oldendquote\endquote
\renewenvironment{quote}[1][]{\oldquote%
\if\relax\detokenize{#1}\relax
``
\else
\begin{center}%
``{\bfseries\itshape #1}%
\end{center}\nobreak
\fi}{''\oldendquote}
\begin{document}
\begin{quote}
Qvidam posuit unum par cuniculorum in quodam loco, qui erat undique
pariete circundatus, ut sciret, quot ex eo paria germinarentur in un
Qvidam posuit unum par cuniculorum in quodam loco, qui erat undique
pariete circundatus, ut sciret, quot ex eo paria germinarentur in un
\end{quote}
\begin{quote}[Here's one with a title]
Qvidam posuit unum par cuniculorum in quodam loco, qui erat undique
pariete circundatus, ut sciret, quot ex eo paria germinarentur in un
Qvidam posuit unum par cuniculorum in quodam loco, qui erat undique
pariete circundatus, ut sciret, quot ex eo paria germinarentur in un
\end{quote}
\end{document}
Best Answer
LaTeX provides the
\DeclareTextFontCommand
declaration precisely for this purpose; in your case, you should say, for example,That is, in the first argument you specify a name of your choosing for the new command; and in the second argument, you put the declarations needed to obtain the family, series, and shape you want to change to.
With this method, you define commands that behave exactly as the predefined commands
\textit
,\textbf
, etc., in thatthey are robust, so they can be used without problems in “moving arguments”;
they automatically take care of the italic correction at both ends, in a way that is consistent with what the predefined commands do (actually, by means of the same algorithm).
Indeed, the predefined commands
\textit
,\textbf
, etc. are themeselves defined by means of\DeclareTextFontCommand
, as you can readily check in the LaTeX sources (e.g., inlatex.ltx
). Note that, given this fact, the name you choose for your new command should, by consistency, begin with\text...
.MWE:
Addition
I forgot to mention, among the benefits of this approach, that your new command will automatically work in math mode too, if you load the
masmath
package (actually, it suffices to load theamstext
package), as the predefined commands like\textit
and\textbf
do.New MWE:
This time I’m also showing the output: