I have written the following commands which first chunk the input text by ; and then make "fractions" out of text that is separated by /. My intention with this is to display genotypes with propper formatting.
\documentclass{article} \usepackage{amsmath} \usepackage{xstring} \newcommand\genoLineDist{.2mm} \newcommand{\genoSplit}[2]{% $\begin{array}{@{}c@{}} \text{\protect#1} \\ \noalign{\vskip\genoLineDist} \hline \noalign{\vskip\genoLineDist} \text{\protect#2} \end{array}$% } \newcommand{\geno}[1]{% \def\remainder{#1}% \def\splitchar{;}% \genoHelper } \newcommand{\genoHelper}{% \IfSubStr{\remainder}{\splitchar}{% \StrBefore{\remainder}{\splitchar}[\firstpart]% \StrBehind{\remainder}{\splitchar}[\remainder]% \genoSplitHelper \ifx\remainder\empty \else \ ;\ \genoHelper \fi }{% \def\firstpart{\remainder}% \genoSplitHelper }% } \newcommand{\genoSplitHelper}{% \IfSubStr{\firstpart}{/}{% \StrBefore{\firstpart}{/}[\upperGeno]% \StrBehind{\firstpart}{/}[\lowerGenoTemp]% \IfSubStr{\lowerGenoTemp}{\splitchar}{% \StrBefore{\lowerGenoTemp}{\splitchar}[\lowerGeno]% \StrBehind{\lowerGenoTemp}{\splitchar}[\remainder]% }{\def\lowerGeno{\lowerGenoTemp}}% \genoSplit{\upperGeno}{\lowerGeno}% }{% \firstpart\unskip% }% } \begin{document} %working \geno{y w ; ap$^{DG3}$ / CyO} %breaks %\geno{ y w ; ap\textsuperscript{DG3} / CyO} \end{document} Now by typing the following command in the document body
\geno{y w ; ap$^{DG3}$ / CyO} We produce this output:
However, when I try to include any commands like \textsuperscript, or symbols like \Male or \Female anywhere in the input string, I run into the following error:
Incomplete \iffalse; all text was ignored after line [line with \geno command]. My best guess is that I'm running into issues with argument expansion in one of the if statements, so I tried placing some \protects in places I suspected could cause issues like when \remainder is first defined in the \geno command and the \IfSubStr to little success. I have also attempted to use the \MakeRobust command like so:
%definitions above here \MakeRobust{\geno} \MakeRobust{\genoHelper} \MakeRobust{\genoSplitHelper} But unfortunately the problem persisted.
Other blind shots in the dark include
- replacing the
\ifxwith\if\relax\detokenize{\remainder}\relax(same error) \detokenizeing the input to\IfSubStr(seems like they all return a false, might be doing something wrong?)- Using various alternatives for the
\genoSplitcommand (same error, I am now positive it is not the issue) - Rewriting all commands to use
\newcommandand\renewcommand(same error)
I have also found this question, but I am not sure this is the same issue I'm experiencing, and the accepted answer (\begingroup\noexpandarg [...] \endgroup) prevents the macro from working.
I'm at my wit's end and would greatly appreciate some insight into what is causing this issue.


