使用 LaTeX2e 宏读取完整的 LaTeX 文件

使用 LaTeX2e 宏读取完整的 LaTeX 文件

我是 LaTeX 平台的新手(学习中),想使用 LaTeX2e 宏读取完整的 LaTeX 文件并进行一些替换。

我的 MWE 是:

        \documentclass{article}
        \usepackage{amsmath}
        \usepackage{ragged2e}
        
        \begin{document}
        \title{Book Title}
        \author{Author Name}
        \maketitle
        
    To address these issues, \textit{WordMelodies} a mobile application to support children in the acquisition of basic literacy skills.
    The app was designed to be inclusive for children with and without VIB, thus promoting interaction between them.
    \textit{WordMelodies} also supports children in exercising basic touchscreen interactions on mobile devices.
    
    \begin{quote}
        The AI for the expected number of XXXX to ZZZZ transitive triads is generally very narrow. Since this statistic reflects relatively high-order structures (because more ties are involved), its range of possible values given the number of edge counts or mutual.
    \end{quote}    
    
    We previously presented a evaluation with visual impairments to assess app usability and accessibility XXXX and ZZZZ.
    Study results unveiled that the app is indeed accessible and usable by people with VIB.
    After the publication remote collection of app usage data, aiming to investigate how end users interact with the system.

\begin{thebibliography}{}

\bibitem{bib1}
Author N., ``Revisiting the Foundations of Network Analysis,'' {\em Science}, {325},~414--416.

\bibitem{bib2}
------ ``Diagnosing Multicollinearity Random Graph Models,'' {\em Research}, {50},~491--530.

\end{thebibliography}
    
    \end{document}

必需的:

  1. 如果LaTeX文件包含XXXX文本,我希望获得LaTeX Compile Error类似的内容LateX Error?
  2. 如果LaTeX文件有ZZZZ文本我想更改\texttt{ZZZZ}
  3. 如果LaTeX文件包含------文本\begin{thebibliography}...\end{thebibliography},我希望获得LaTeX Compile Error类似的内容LateX Error?

如何做到LaTeX仅使用而不使用XeLaTeX/LuaLaTeX

提前感谢您的支持。

我的书目宏:

\makeatletter
\renewenvironment{thebibliography}[1]{%
 \bibsection
 \parindent\z@
 \bibpreamble
 \bibfont
 \list{\@biblabel{\the\c@NAT@ctr}}{\@bibsetup{#1}\global\c@NAT@ctr\z@}%
 \ifNAT@openbib
   \renewcommand\newblock{\par}%
 \else
   \renewcommand\newblock{\hskip .11em \@plus.33em \@minus.07em}%
 \fi
 \sloppy\clubpenalty4000\widowpenalty4000
 \sfcode`\.\@m
 \let\NAT@bibitem@first@sw\@firstoftwo
    \let\citeN\cite \let\shortcite\cite
    \let\citeasnoun\cite
}{%
 \bibitem@fin
 \bibpostamble
 \def\@noitemerr{%
  \PackageWarning{natbib}{Empty `thebibliography' environment}%
 }%
 \endlist
 \bibcleanup
}%
\makeatother

答案1

如果你只想替换quote环境中的标记,你可以使用\NewEnvironmentCopy和参数类型重新定义它+b,它代表环境的主体。现在l3你可以用其他标记替换主体内的标记,例如:

\documentclass{article}
\usepackage{amsmath}
\usepackage{ragged2e}

\NewEnvironmentCopy{latexquote}{quote}
\ExplSyntaxOn
\tl_new:N \l__quotebody_tl
\RenewDocumentEnvironment { quote } { +b }
  {
    \tl_set:Nn \l__quotebody_tl { #1 }
    \tl_replace_all:Nnn \l__quotebody_tl { XXXX } { \LaTeX{}~Compile~Error }
    \tl_replace_all:Nnn \l__quotebody_tl { ZZZZ } { \textit{\texttt{ZZZZ}} }
    \latexquote
    \l__quotebody_tl
    \endlatexquote
  }
  {
  }
\ExplSyntaxOff

\begin{document}
\title{Book Title}
\author{Author Name}
\maketitle
    
To address these issues, \textit{WordMelodies} a mobile application to support children in the acquisition of basic literacy skills.
The app was designed to be inclusive for children with and without VIB, thus promoting interaction between them.
\textit{WordMelodies} also supports children in exercising basic touchscreen interactions on mobile devices.

\begin{quote}
    The AI for the expected number of XXXX to ZZZZ transitive triads is generally very narrow. Since this statistic reflects relatively high-order structures (because more ties are involved), its range of possible values given the number of edge counts or mutual.
\end{quote}    

We previously presented a evaluation with visual impairments to assess app usability and accessibility XXXX and ZZZZ.
Study results unveiled that the app is indeed accessible and usable by people with VIB.
After the publication remote collection of app usage data, aiming to investigate how end users interact with the system.

\end{document}

在此处输入图片描述

有关expl3语法和 LaTeX3 函数的更多信息,如tl_replace_all:Nnn(甚至\regex_replace_all:nnN)请参阅LaTeX3 内核

但是,我认为这样的事情真的没有什么意义。正如 David 在评论中所说:如果你想在文本中使用占位符,那么应该将其替换,将这些占位符定义为宏并使用这些宏会更有意义:

\documentclass{article}
\usepackage{amsmath}
\usepackage{ragged2e}

\newcommand*\XXXX{XXXX}
\newcommand*\ZZZZ{ZZZZ}

\AddToHook{env/quote/begin}{%
  \renewcommand*\XXXX{%
    \GenericError{}
      {LaTeX Error: \string\XXXX\space used}
      {Don't do it.}
      {Usage of \string\XXXX\space inside quote is not allowed.}%
  }%
  \renewcommand*\ZZZZ{\textit{\texttt{ZZZZ}}}%
}

\begin{document}
\title{Book Title}
\author{Author Name}
\maketitle
    
To address these issues, \textit{WordMelodies} a mobile application to support children in the acquisition of basic literacy skills.
The app was designed to be inclusive for children with and without VIB, thus promoting interaction between them.
\textit{WordMelodies} also supports children in exercising basic touchscreen interactions on mobile devices.

\begin{quote}
    The AI for the expected number of \XXXX{} to \ZZZZ{} transitive triads is generally very narrow. Since this statistic reflects relatively high-order structures (because more ties are involved), its range of possible values given the number of edge counts or mutual.
\end{quote}    

We previously presented a evaluation with visual impairments to assess app usability and accessibility \XXXX{} and \ZZZZ{}.
Study results unveiled that the app is indeed accessible and usable by people with VIB.
After the publication remote collection of app usage data, aiming to investigate how end users interact with the system.

\end{document}

相关内容