1

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

enter image description here

Then by switch modes it could instead output this from the same source code.

In text only mode

enter image description here

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.

Algeboy
  • 249
  • 1
    I'll have to give significant thought to this...the issue of course is that the tokcycle pseudo-environment \spt is looking for an actual ending token \endspt on which to halt its operation. In contrast, the LaTeX environment construction makes it so that placing \endspt in the environment close-out code will never be seen within the actual environment. One option may be to have alternate definitions of \spt and \endspt, where it is \let to \relax or \empty when you want to run the code as actual math. – Steven B. Segletes Feb 21 '24 at 17:17
  • 1
    Please see my edit, in which I incorporate \spt...\endspt into the renewed equation environment. – Steven B. Segletes Feb 21 '24 at 20:35

1 Answers1

2

EDIT: to incorporate \spt...\endspt directly into the renewed equation environment. Additionally, what this MWE does, is to allow normal math rendering to be switched to accessible rendering with a single-line change to the input file.

In this MWE, the document presents math in the normal LaTeX way. To get the accessible version, merely uncomment the first line of the file, \AtBeginDocument{\speakify}.

%\AtBeginDocument{\speakify}
\documentclass{amsart}

%% Equalspeak commands \usepackage{tokcycle, environ} % convert math to english-ish

\newcommand\speakify{% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Math Overrides \RenewEnviron{equation}{% \stepcounter{parentequation}% \begin{center} \begin{minipage}{0.9\textwidth} {\small begin equation \theparentequation}

\expandafter\spt\BODY\endspt
\\
{\small end equation \theparentequation}
\end{minipage}
\end{center}

} % \renewenvironment{pmatrix}{ \ \begin{minipage}{0.9\textwidth} {\small begin matrix } }{ {\small end matrix} \end{minipage} \ } \renewcommand{\in}{~in~} \renewcommand{\mathbb}[1]{bold ##1} \renewcommand{\Null}{~null space of:~} } % % %% TOKENIZER \tokcycleenvironment\spt {\tcremap[x]{##1}} {\processtoks{##1}} {\tcremap[1]{##1}} {\addcytoks{##1}} % \newcommand{\Null}{} % \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} \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}
\end{equation} But if you cannot see the expression or make out the symbols then you might prefer the words. \end{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Normal result:

enter image description here

With \speakify turned on:

enter image description here