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 really like using UTF-8 greek letters in my latex code source and I use utf8x to convert them into \textalpha commands and then I define the \textalpha commands in a separate file where I write this, for each greek letter:

\newcommand{\textalpha}{\ensuremath{\alpha}}

And can even afford the luxury to use \varepsilon and \varphi.

This is actually the least intrusive and the most compatible way I found of doing this. (Well actually a little sed-parser was a lot more versatile and efficient because I knew what was going on but that's a very intrusive method)

Sadly this ... does not work with beamer because it seems to already have defined \textbeta and \textmu. Yes, only them. I don't know why.

Here is how to reproduce this. (This compiles. If you uncomment anything it won't compile)

\documentclass{beamer}
\usepackage[utf8x]{inputenc}
\newcommand{\textalpha}{\alpha}
%\newcommand{\textbeta}{\beta}
%\newcommand{\textmu}{\mu}
\begin{document}
  $α$
  % $β$
  % $μ$
\end{document}

Does somebody know why? And also, how to overcome this? If I use \renewcommand it works in beamer files but it won't work in non-beamer files. Maybe there is a \forcerenewcommand that I don't know about?

share|improve this question
1  
maybe you want to use \providecommand which does nothing, if the command already exist and does a \newcommand otherwise. –  Peter Breitfeld May 16 '12 at 13:30
    
@PeterBreitfeld thank you I will definitely use this as a workaround (with renewcommand). –  jmad May 16 '12 at 13:58
add comment

1 Answer

I have no idea why beamer has a \textbeta. Maybe someone else can give that answer.

There of course are ways to overwrite an existing macro.

For example you can use \def to overwrite any existing macro definition. This lacks \newcommand's syntax, though. So you could instead define a new command that checks if the command already exists and depending on the ckeck either invokes \newcommand or \renewcommand.

\documentclass{beamer}
\usepackage[utf8x]{inputenc}

\makeatletter
% check if csname is defined
\newcommand*\checkfor[1]{%
  \ifx#1\AMostCertainlyUndefinedCommand
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
% define in any case
\newcommand*\forcenewcommand[1]{%
  \checkfor{#1}{\newcommand{#1}}{%
    \GenericWarning{}{Warning: redefining \string#1}{}%
    \renewcommand{#1}}}
\makeatother

\newcommand{\textalpha}{\alpha}
% this works, of course:
\def\textbeta{\beta}
% as will the new definition command:
\forcenewcommand{\textmu}{\mu}

% for demonstration purposes only:
\forcenewcommand\textbf[1]{(#1)}

\begin{document}
  $α$
  $β$
  $μ$
  \textbf{A}
\end{document}
share|improve this answer
    
Thank you. Is using \checkfor any better than doing \providecommand{\textbeta}{DEBUG-providecommand} \renewcommand{\textbeta}{\beta}? (Apart from the warning) –  jmad May 22 '12 at 13:44
    
@jmad I woudn't think so. Except less typing for you maybe if you don't have to define each command twice... –  cgnieder May 22 '12 at 14:15
add comment

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.