Try this for issue 1. I don't understand enough about issue 2 to try to resolve it.
The main issue was that the original version of \calbf
had no handling of expansion at all. So what happened was that \calbf
saw a single token \BODY
and just passed it through and said \stackon[\calup]{\BODY}{\kern\calover\BODY}
. The reason that \calbf
tries to pass one token to \calup
at a time is presumably due to the fact that passing a whole block of text destroys line breaking.
So changing \calbf
to expand its argument helps. I use the \romannumeral
trick to recursively expand the first token of \calbfhelpA
. In this case, the first token is \BODY
and it expands and dumps out the rest of everything.
Another issue then arises which is that the only reason it worked to say \"a
before was because \calbf
wasn't successfully separating out individual characters of the input because it was all in \BODY
. The fix requires testing inside of \calbfhelpB
whether the first argument is a macro. If the first argument is a macro, save it and grab the next token as well. We also run into trouble if we see a \par
or \\
token, so we test for those separately.
\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{environ}
\usepackage[scale=1]{miama}
\usepackage{stackengine}
\def\useanchorwidth{T}
\def\stacktype{L}
\def\stackalignment{l}
\def\calup{.2pt}
\def\calover{.15pt}
\makeatletter
% Terminal token to signal end of input.
% We give it a unique definition so that `\ifx\endtoken\anythingelse` always tests false.
% Since we're using fexpansion, we need an extra `\noexpand` to prevent it from getting
% turned into something else.
\def\calbf@endtoken{\noexpand\calbf@endtoken}
% Use \romannumeral trick to "f expand" argument
% We are going to parse by spaces, so we need to add a terminal space and \relax
% so we can tell when we are done.
\def\calbf#1{\expandafter\calbf@\romannumeral-`0#1 \calbf@endtoken}
% Needs to be \long in case argument is a \par token.
% #1 - a single word
\long\def\calbf@#1 {%
\calbf@handleword{}#1\calbf@endtoken
% Check if we are done. If not, fexpand rest of input and recurse.
\@ifnextchar\calbf@endtoken{}{\ \expandafter\calbf@\romannumeral-`0}%
}
% Helper macro to test for equality.
\long\def\calbf@ifx#1#2{%
\ifx#1#2\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
}
% Test if argument is a macro (checks if \string#1 contains multiple characters).
\long\def\calbf@ifmacro#1{%
\expandafter\ifx\expandafter$\romannumeral-`0\expandafter\@gobble\string#1$%
\expandafter\@secondoftwo
\else
\expandafter\@firstoftwo
\fi
}
\long\def\calbf@handleword#1#2{%
\calbf@ifx{#2}{\calbf@endtoken}{}{% we're done with this word
\calbf@ifx{#2}{\par}{%
#2\calbf@handleword{}% just pass \par tokens through
}{%
\calbf@ifx{#2}{\\}{%
#2\calbf@handleword{}% just pass \\ tokens through
}{%
\calbf@ifmacro#2{% If it's an accent, save it and grab the argument too.
\calbf@handleword{#1#2}%
}{%
\stackon[\calup]{#1{#2}}{\kern\calover#1{#2}}% Otherwise print it.
\calbf@handleword{}%
}%
}}}%
}
\NewEnviron{MyCal}{%
%\fmmfamily
\noindent
\calbf{Test0}\\ \BODY \\\\
\calbf{\BODY}%
}
\makeatother
\begin{document}
\def\calup{.3pt}
\def\calover{.3pt}
\"{ab}
\begin{MyCal}
MyCal:\\
Test1: %ä.ö.ü.Ä.Ö.Ü.ß.\ss.
\par
abcd
\"e \"i \"a \"o \"u \"e\"i\"a\"o\"u \"{abcd} {1234}
\end{MyCal}
\par\vspace{1em}
%\calbf{ä.ö.ü.Ä.Ö.Ü.ß.\ss \ldots á é ó í ú \ldots \"e \"i \"a \"o \"u}
\end{document}