[texhax] single commands to start and end superscript

Susan Dittmar SDittmar at eureca.de
Tue Feb 12 19:13:40 CET 2008


Quoting Matthew Leingang (leingang at math.harvard.edu):
> On Feb 12, 2008, at 10:01 AM, Susan Dittmar wrote:
> >I would like to change an existing macro in a LaTeX document. Said
> >macro parses a sequence of characters, outputting them one by one,
> >changing fonts or substituting symbols when encountering special
> >characters.
> >
> >What I would like to add is a 'switch to superscript' and a 'leave
> >superscript' character. Thus, I need single commands for those two
> >actions.
> >
> >I do not know enough of the bare bones to come up with those, so  any
> >help would be appreciated.
> 
> Sounds interesting.  Can you post code of the existing macro and some
> examples of it in use?

Gladly.

------
\documentclass{scrartcl}

% Some font declarations (as I did not want to shorten the parser macro)
\newcommand{\ChFont}{\large\fontfamily{\sfdefault}\fontseries{sbc}\fontshape{n}\selectfont}
\newcommand{\ChBkFont}{\ChFont\fontseries{m}\selectfont}
\newcommand{\ChBassFont}{\small\bf\sf}

% call the (recursive) parser and make sure it terminates:
\newcommand{\chord}[1]{%
	\ChFont\sbChord#1\relax%
}
% the parser itself (originally from songbook.sty):
\def\sbChord#1{%
	\ifx#1\relax%
		\let\next=\relax%
	\else%
		\ifx#1##% double sharp because we're inside a \def
			$\sharp$%
		\else%
			\ifx#1b%
				$\flat$%
			\else%
				\ifx#1/%
					\ChBassFont /%
				\else%
					\ifx#1[%
						\bgroup\ChBkFont [\egroup%
					\else%
						\ifx#1]%
							\bgroup\ChBkFont ]\egroup%
						\else%
							#1%
						\fi%
					\fi%
				\fi%
			\fi%
		\fi%
		\let\next=\sbChord%
	\fi%
	\next%
}

\begin{document}

``simple'' example:\\
\chord{C#/Bb}

what I have now for superscripts: \\
\chord{C#{\textsuperscript{7}}/Bb}

% what I would like for superscripts (I think I know how to find the point
% for the `end superscript' position, that's not yet part of the macro):
%\chord{C#^7/Bb}

\end{document}
------



More information about the texhax mailing list