Please consider the following code:
\documentclass{article}
\usepackage{ruby}
\newcommand{\strsymbol}{\large\bfseries∗}
\newcommand{\unssymbol}{\large·}
\newcommand{\str}[1]{\textbf{\ruby{#1}{\strsymbol}}{}}
\newcommand{\uns}[1]{\ruby{#1}{\unssymbol}{}}
\begin{document}
\uns{A} \uns{po}\uns{ly}\str{syl}\uns{la}\uns{ble} \uns{should} \uns{be} \str{fun} \uns{to} \uns{de}\str{fine}.
\end{document}
It generates output like this:
(Well I use nicer fonts and symbols, but you get the idea).
As you can see, that code is quite unwieldly. Ideally I'd like some function to accept an argument like this:
\stress{A po-ly*syl*la-ble should be *fun* to de*fine*.}
In fact, the working example up there wasn't written by hand; it's the output of some ugly Emacs Lisp code I wrote to convert the nicer argument format. It just loops over the characters handling the several different cases (*
, -
, Unicode alphanumerics, and space/punctuation), keeping track of state to start and end the Latex commands accordingly.
I'm totally new to Tex programming, and was wondering whether a Latex solution is possible. I have to use Xetex because of reasons. My attempts didn't get very far; I can't loop over strings with \@tfor
because it eats inner whitespace, and even if I could, I don't know how to write a command piecemeal spanning many loop interactions (like \ruby{
… }
). I saw the answer about Expandable 'character scanning' command that preserves spaces , but I couldn't even being to figure out how one should modify the sample code to implement something like this.
What's the best approach to write a Latex macro accepting an argument like this?