环境内的 tokcycle 标记器错误

环境内的 tokcycle 标记器错误

延伸505462,我在许多数学命令上添加了替代文本选项,以便我可以在文本和样式化方程输出之间切换。我无法使用环境调用 tokcycle。这是工作代码。

\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}

我需要标记器很好地读出矩阵的条目,但是每当我将它\spt放入\endspt我的\renewenvironment{equation}{...\spt}{\endspt...}矩阵时,我都会收到编译时错误,并且没有带有错误消息的输出:

Runaway argument?
{
! Paragraph ended before \\tcremap was complete.
<to be read again> 
                   \par 

看起来好像标记器参与了序言,而不是等待它在文本主体中被调用。


目标是将序言放入包中,以便我可以以两种模式运行。一种是常规 latex,另一种是输出

常规模式

在此处输入图片描述

然后通过切换模式,它可以从相同的源代码输出它。

纯文本模式

在此处输入图片描述

除了手动插入和注释掉之外,\spt\endspt可以起作用,但如果不能将其折叠进去,\renewenvironment似乎我每次都只能手动更改实际文件。

答案1

编辑:直接合并\spt...\endspt到更新的equation环境中。此外,此 MWE 的作用是允许通过对输入文件进行单行更改将普通数学渲染切换为可访问渲染。

在此 MWE 中,文档以常规 LaTeX 方式呈现数学。要获取可访问的版本,只需取消注释文件的第一行\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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

正常结果:

在此处输入图片描述

\speakify开启时:

在此处输入图片描述

相关内容