2

I use the miama font to simulate short (a couple of lines) handwritten pieces of text. As the font is rather light, I use an adaption of Steven B. Segletes solution from How to bold custom calligraphic text

  1. The problem is, that giving \BODY as \calbf argument, it swallows all line breaking. (But it handles UTF-8 chars with german Umlauts etc. well). This has nothing to do with the miama font. Line breaking is affected also without it.
  2. I also wonder about the fact that calling \calbf as shown in the last (outcommented) line, it raises this error:

    ! Package inputenc Error: Invalid UTF-8 byte sequence.

    See the inputenc package documentation for explanation. Type H for immediate help. ...

    l.61 ...á é ó í ú \ldots \"e \"i \"a \"o \"u} enter code here

Can someone show me how to handle (especially) issue 1?

\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}
\def\calbf#1{\calbfhelpA#1 \relax\relax}
\def\calbfhelpA#1 #2\relax{%
  \calbfhelpB#1\relax\relax%
  \ifx\relax#2\else\ \calbfhelpA#2\relax\fi
}
\def\calbfhelpB#1#2\relax{%
  \stackon[\calup]{#1}{\kern\calover#1}%
  \ifx\relax#2\else
    \calbfhelpB#2\relax%
  \fi
}

\NewEnviron{MyCal}%
{%
  \fmmfamily%
  \noindent%
  \calbf{Test0}\\ \BODY \\\\ \calbf{\BODY}%
}

\begin{document}
\def\calup{.3pt}
\def\calover{.3pt}


\begin{MyCal}
MyCal:\\
Test1: ä.ö.ü.Ä.Ö.Ü.ß.\ss.
\par
á é ó í ú

\"e \"i \"a \"o \"u
\end{MyCal}
\par\vspace{1em}
%\calbf{ä.ö.ü.Ä.Ö.Ü.ß.\ss \ldots  á é ó í ú \ldots \"e \"i \"a \"o \"u}
\end{document}

1 Answer 1

2

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} 
5
  • Thanks. It works also for Test1: ä.ö.ü.Ä.Ö.Ü.ß.\ss. uncommented. But ` MyCal:\\ ` produces *MyCal:= **
    – Jack
    Commented Dec 23, 2019 at 20:42
  • You're saying it strips a leading space? Commented Dec 23, 2019 at 21:14
  • No. I wanted to say that it raises this error: ! Extra }, or forgotten \endgroup. And after pressing 'q' it produces the output with MyCal:=*
    – Jack
    Commented Dec 24, 2019 at 9:07
  • @Jack I think I fixed that error. Commented Dec 24, 2019 at 16:28
  • Yes, you did. But now the line ä.ö.ü.Ä.Ö.Ü.ß. produces an error. So I am still looking for improvement. But thanks for your efforts.
    – Jack
    Commented Dec 29, 2019 at 19:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .