Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

obeylines实现在参数中换行导致cases,aligned等环境出错 #37

Closed
rch2008 opened this issue May 30, 2019 · 4 comments
Closed
Labels
Macro/core Related to TeX core macros.

Comments

@rch2008
Copy link

rch2008 commented May 30, 2019

\documentclass{article}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{ifthen}
\newif\ifteacher    
\usepackage{ctex}
\usepackage{color}

\makeatletter
\newcommand\testE[2]{\item[5.]#1\par#2\par
	\ifteacher\begingroup\obeylines\expandafter\testEaux
	\else\expandafter\@gobble\fi}
\newcommand\testEaux[1]{\indent\color{red}#1\par\endgroup}
\makeatother
%这里进行了全局修改,修补了cases环境的断行问题,
%修改"的类别码存在隐患,
%有没有别的方法解决这个问题,
%能定义一个宏代替实现换行也行,
%最好是能够通过重定义cases环境实现
\catcode`\"=5
\begin{document}
	\teachertrue

	\begin{itemize}%\cprotect[mmm]
		\testE{ID}{题干.}{解:由于更改了行结束符号的catcode,导致数学环境出错
			$\begin{cases}"
			\log _{a}4<3\\"
			\log _{a}8>3"
			\end{cases}$
		}
	\end{itemize}
\end{document}
@qinglee
Copy link
Member

qinglee commented May 30, 2019

问题出在 \par 用在数学环境中会出错,需要对 \obeylines 的定义稍加调整。

\makeatletter
\begingroup
\catcode\active\active
\protected\gdef\mathobeylines{%
  \catcode\active\active \let^^M\math@obeylines}
\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[1]{\indent\color{red}#1\par\endgroup}
\makeatother

@rch2008
Copy link
Author

rch2008 commented May 30, 2019

十分感谢李老师的再次耐心解答,真心感谢!

@rch2008
Copy link
Author

rch2008 commented Jun 10, 2019

李老师,您好,最近用您写的代码有发现了一个新问题,之前我没有考虑到 tabular 环境,现在如果答案中包含 tabular 环境且用了 \hline 就会报错,不知道该怎么解决,尝试了一下用 @currenvir 去做判定,但是我没有做成功,不知道李老师有没有好办法能解决,麻烦您了。

\begin{itemize}
\testE{15}{设实数$x$$y$满足约束条件$\begin{cases}%
x\geqslant 0\
x\leqslant y\
x+y\geqslant 2
\end{cases}%
$,则$z=2x+y$的取值范围为 .
}%
{解:由约束条件$\begin{cases}%
x\geqslant 0\
x\leqslant y\
x+y\geqslant 2
\end{cases}%
$作出可行域如图,
化$z=2x+y$$y=-2x+z$,由图可知,当直线$y=-2x+z$$A$时,直线在$y$轴上的截距最小,$z$有最小值为$2$${\therefore}z=2x+y$的取值范围为$[2$$+\infty)$\hh\color{blue}故答案为:$[2$$+\infty)$\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}
}

@qinglee

@stone-zeng stone-zeng added the Macro/core Related to TeX core macros. label Jun 10, 2019
@muzimuzhi
Copy link
Collaborator

既然是新问题,建议使用新标题、开一个新 issue。

这样,既能方便用户「读标题以了解 issue 大意」,也可能提高搜索准确率。如果需要在新 issue 中引用当前 issue(#37),GitHub 也提供了多种便利方式

@rch2008 rch2008 closed this as completed Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Macro/core Related to TeX core macros.
Projects
None yet
Development

No branches or pull requests

4 participants