Extending on 505462, I am putting alternate text options on a number of math commands so that I can switch between a text and styled equation output. I am having trouble invoking tokcycle with environments. Here is the working code.
\documentclass{amsart}
%% Equalspeak commands
\usepackage{tokcycle} % convert math to english-ish
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Math Overrides
\renewenvironment{equation}{
\stepcounter{parentequation}
% \begin{speakifytext}
\begin{center}
\begin{minipage}{0.9\textwidth}
{\small begin equation \theparentequation}
}{
\
{\small end equation \theparentequation}
\end{minipage}
\end{center}
% \end{speakifytext}
}
\renewenvironment{pmatrix}{
\
\begin{minipage}{0.9\textwidth}
{\small begin matrix }
}{
{\small end matrix}
\end{minipage}
\
}
\renewcommand{\in}{~in~}
\renewcommand{\mathbb}[1]{bold #1}
\newcommand{\Null}{~null space of:~}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TOKENIZER
\tokcycleenvironment\spt
{\tcremap[x]{##1}}
{\processtoks{##1}}
{\tcremap[1]{##1}}
{\addcytoks{##1}}
\newcommand\tcmapto[3][\noexpand\pauseafter]{%
\expandafter\def\csname tcmapto\string#2\endcsname{\text{#3 }#1}}
\newcommand\tcmaptomacro[3][\noexpand\pauseafter]{%
\expandafter\def\csname tcmapto\string#2\endcsname{#3#1}}
\newcommand*\tcremap[2][1]{\ifcsname tcmapto\string#2\endcsname
\addcytoks[#1]{\csname tcmapto\string#2\endcsname}\else\addcytoks{#2}\fi}
\newcommand\pauseafter[1]{\tctestifcatnx#1\relax{#1}{#1,}}
%% READ PARENS
\tcmapto[] ({, left paren,}
\tcmapto[] ){, right paren ,}
%% READ BRACE
\tcmapto[] \left{}%gobble size of brace
\tcmapto[] \middle{}%gobble size of stroke
\tcmapto[] \right{}%gobble size of brace
%% READ BRACE
\tcmapto[] {{ the set of:}
\tcmapto[] }{ end of set}
%% READ SUB/EXP
\tcmapto ^{ raised to the power}
\tcmapto _{ sub}
\tcmapto +{ plus}
\tcmapto -{ minus}
\tcmapto |{ such that}
%% READ FRACTION
\tcmaptomacro[] \cdot\readcdot
\newcommand\readcdot{\text{\small , times }}
%% READ FRACTION
\tcmaptomacro[] \frac\readfrac
\newcommand\readfrac[2]{\text{\small, the fraction, } #1%
\text{\small , divided by, }#2%
\text{\small , end fraction, }}
% matrix read aloud
\tcmapto &{next }
\tcmapto ,{ comma }
\tcmapto \{\small end row}
\tcmapto |{ such that }
\title{Latex gives you options}
\author{James B.\ Wilson}
\date{\today}
\begin{document}
\maketitle
For some people seeing an expression in symbols does a better job than words. For example:
\begin{equation}
\spt % I'd like this to go in equation environment
\Null
\begin{pmatrix}
1 & 1 & 2\ 2 & 2 & 4
\end{pmatrix}
= \left{
a\cdot
\begin{pmatrix}
1 \ 0 \ -\frac{1}{2}
\end{pmatrix}
+
b\cdot
\begin{pmatrix}
1 \ -1 \ 0
\end{pmatrix}
:
a,b\in \mathbb{R}
\right}
\endspt % I'd like this to go in equation environment
\end{equation}
But if you cannot see the expression or make out the symbols then you might prefer the words.
\end{document}
I need the tokenizer to read out the entries of a matrix nicely, but whenever I put \spt and \endspt into my \renewenvironment{equation}{...\spt}{\endspt...} I get compile time errors and no output with error message:
Runaway argument?
{
! Paragraph ended before \\tcremap was complete.
<to be read again>
\par
It seems as if the tokenizer engages in the preamble instead of waiting for it be called in the body of the text.
The goal is to drop the preamble into a package so that I can run in two modes. One does regular latex and outputs
In regular mode
Then by switch modes it could instead output this from the same source code.
In text only mode
Other than manually inserting and commenting out the \spt and \endspt it works, but without being able to fold that into the \renewenvironment it seems I'm stuck with manually changing the actual file each time.




\sptis looking for an actual ending token\endspton which to halt its operation. In contrast, the LaTeX environment construction makes it so that placing\endsptin the environment close-out code will never be seen within the actual environment. One option may be to have alternate definitions of\sptand\endspt, where it is\letto\relaxor\emptywhen you want to run the code as actual math. – Steven B. Segletes Feb 21 '24 at 17:17\spt...\endsptinto the renewedequation environment. – Steven B. Segletes Feb 21 '24 at 20:35