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.

In LaTeX, 'active' declarations (commands without argument) like \Gamma produce printable characters to the output stream while 'passive' ones like \itshape do not. Is there a macro (or how to write one) which, given a LaTeX declaration as argument, will resolve whether the declaration is active or passive?

I need to be able to resolve this issue in order to correctly format the rendering of an input LaTeX argument with embedded declarations.

share|improve this question
    
Welcome to TeX.sx! A tip: you can use backticks ` to mark your inline code as I did in my edit. –  doncherry Aug 7 '11 at 17:31
1  
The distinction between commands with and without arguments is not equivalent to that between those that write to the output document and those that do not - consider \textit vs \itshape and all the analogous font-changing commands for example. –  Ant Aug 7 '11 at 17:32
3  
Not really, your distinction of "active" and "passive" macros doesn't exist like that. Actually \textit is much more 'active' because it's changing the font(!) while \Gamma only prints a character. Also note that 'active' normally mean active characters with (La)TeX, like ~. You could of course use a savebox (see \sbox) and measure the width of the resulting text which should be zero for "passive" macros. However, you need to provide the right number of dummy arguments.... –  Martin Scharrer Aug 7 '11 at 17:41
    
My use of the descriptions 'active' and 'passive' were coined ad hoc to distinguish between those declarations that write to the output stream and those that do not. I am not concerned with what is going on 'behind the scene' so to speak. I think you misunderstand my question. I need to know a priori if a LaTex command will or will not produce output. For example I need to be able to determine for the Latex inputfor any conmmand \declaration –  darrelld Aug 7 '11 at 18:05
4  
@darrelld: I understood you correctly and my answer stands: You can't! The only way is to measure the result. If you explain your actual problem than we might be able to help you better. –  Martin Scharrer Aug 7 '11 at 18:17
show 8 more comments

1 Answer

This is not an answer to the question as currently stated. Given some comments of darrelld, I believe that the goal is to define a macro, \TitleCase, which puts its argument in, well, title case. This can be done with varying degrees of robustness, but one way is to read tokens one at a time and convert letters using \uppercase and \lowercase.

Here, \TitleCase@case is at all times either \uppercase or \lowercase: it is set to \uppercase at the very start of the \TitleCase command, and after each space. It is set to \lowercase by any letter.

The result is stored one piece at a time into \TitleCase@tl, and used at the end.

\makeatletter
\newcommand*{\TitleCase@tl}{}
\newcommand*{\TitleCase@case}{}
\newcommand*{\TitleCase@marker}{\TitleCase@marker}
\DeclareRobustCommand{\TitleCase}[1]
  {%
    \let\TitleCase@tl\empty
    \let\TitleCase@case\uppercase
    \TitleCase@#1\TitleCase@marker
    \TitleCase@tl
  }
\newcommand*{\TitleCase@}{\futurelet\@let@token\TitleCase@@}
\newcommand*{\TitleCase@@}
  {%
    \ifcase 0%
        \ifcat\noexpand\@let@token\bgroup 1\fi
        \ifx\@let@token\@sptoken 2\fi
        \ifx\@let@token\TitleCase@marker 3\fi
      \relax
        \expandafter\TitleCase@normal
    \or \expandafter\TitleCase@group
    \or \expandafter\TitleCase@space
    \or \expandafter\@gobble
    \fi
  }
\newcommand{\TitleCase@normal}[1]
  {%
    \TitleCase@case
      {%
        \expandafter\def\expandafter\TitleCase@tl\expandafter
          {\TitleCase@tl #1}%
      }%
    \ifcat A\noexpand\@let@token
      \let\TitleCase@case\lowercase
    \fi
    \TitleCase@
  }%
\newcommand{\TitleCase@group}[1]
  {%
    \begingroup
      \let\TitleCase@tl\empty
      \TitleCase@ #1\TitleCase@marker
      \expandafter
    \endgroup
    \expandafter\expandafter\expandafter\def
    \expandafter\expandafter\expandafter\TitleCase@tl
    \expandafter\expandafter\expandafter{%
      \expandafter\TitleCase@tl\expandafter{\TitleCase@tl}}%
    \TitleCase@
  }
\newcommand{\TitleCase@space}
  {\afterassignment\TitleCase@space@\let\@let@token= }
\newcommand{\TitleCase@space@}
  {%
    \let\TitleCase@case\uppercase
    \expandafter\expandafter\expandafter\def
    \expandafter\expandafter\expandafter\TitleCase@tl
    \expandafter\expandafter\expandafter{\expandafter\TitleCase@tl\space}%
    \TitleCase@
  }
\makeatother
\documentclass{article}
\begin{document}
  \section{\TitleCase{helLo, \itshape wo\textup{Rl}D!}}
\end{document}
share|improve this answer
    
@ Bruno Le Floch: Thank you for putting time and thought into this macro. It is along the same lines as I have already done but, not being a TEXnician, using higher level LaTex commands from the xstring package. Your macro renders what I would call Initial Capital Case which is somewhat different from what I understand by the more subtle Title Case. Never mind, I think that I can see my way forward using save boxes as Martin Scharrer suggests. Strangely I have tried that approach before but without success till now. –  darrelld Aug 8 '11 at 16:18
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.