Giter Club home page Giter Club logo

Comments (1)

rch2008 avatar rch2008 commented on August 12, 2024

目前我比较满意的解决办法
在进入tabular之前\let^^M\empty

\protected\gdef\tabulartest{%
	\catcode\active\active\let^^M\empty}
\usepackage{etoolbox}
\AtBeginEnvironment{tabular}{\begingroup\tabulartest}
\AfterEndEnvironment{tabular}{\endgroup}
\documentclass{ctexbook}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{ifthen}
\newif\ifteacher    
\usepackage{color}
\usepackage{etoolbox}
\makeatletter
\begingroup
\catcode`\^^M\active
\protected\gdef\mathobeylines{%
  \catcode`\^^M\active \let^^M\math@obeylines}
\protected\gdef\tabularobeylines{%
	\catcode`\^^M\active \let^^M\empty}
\endgroup
\AtBeginEnvironment{tabular}{\begingroup\tabularobeylines}
\AfterEndEnvironment{tabular}{\endgroup}

\protected\def\math@obeylines{%
  \unless\ifmmode\expandafter\par\fi}

\newcommand\testE[2]{\item[5.]#1\par#2\par%
	\ifteacher\begingroup\mathobeylines\expandafter\testEaux
	\else\expandafter\@gobble\fi}
\newcommand\testEaux{\futurelet\nextMacro\wait}
\newcommand\wait[1]{\ifx\nextMacro\math@obeylines\expandafter\testEaux\else \indent\color{red}#1\endgroup\fi}
\makeatother

\begin{document}
	\teachertrue
	下面内容可以编译之后再看
	\def\temp{\textasciicircum\textasciicircum M}
	\begin{itemize}
		\testE{ID}{由于更改了行结束符号\temp 的catcode,导致tabula环境中使用\string\hline 出错.}
		{解:加了数学模式的判断,数学环境不会出错了。
		$\begin{cases}
		x\geqslant 0\\
		x\leqslant y\\
		x+y\geqslant 2
		\end{cases}$
		tabular环境需要在\string\begin\{tabular\}之前将\temp 设置为空\string\let\temp\string\empty\string\AtBeginEnvironment\{tabular\}\{\string\begingroup\string\tabularobeylines\}
		\string\AfterEndEnvironment\{tabular\}\{\string\endgroup\}
		\begin{tabular}{|c|c|c|c|}
		\hline
		$x$ & $(0$$\ln (2k))$ & $\ln (2k)$ & $(\ln (2k)$$k) $\\
		\hline
		$f'(x)$ & $-$ & $0$ & $+ $\\
		\hline
		$f(x)$ & ${\searrow}$ & 极小值 & ${\nearrow} $\\
		\hline
		\end{tabular}
		后面可以继续obeylines
别急丽丽
		}
	\end{itemize}
\end{document}

from forum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.