过滤现有问题中的部分问题

过滤现有问题中的部分问题
    \documentclass[12pt,a4paper]{article}
\newtheorem{ex}{Exam}
\def\choice{....????} %Help me define the \ choice command and ex enviroment
    \begin{document}
    
   \begin{ex}
    A question 
    \end{ex}
    \begin{ex}
    A question 
    \end{ex}
    \begin{ex}
    A question 
    \end{ex}
    \begin{ex}
    A question 
    \end{ex}
    \begin{ex}
    A question 
    \end{ex}
    \begin{ex}
    A question 
    \end{ex}
    \begin{ex}
    A question 
    \end{ex}
    \begin{ex}
    A question 
    \end{ex}
    \begin{ex}
    A question 
    \end{ex}
    \begin{ex}
    A question 
    \end{ex}
    \choice{5}%When executing this command, the first 5 questions will be compiled and displayed on the pdf file
    \end{document}

编译后,你将得到一个包含前5个问题的Pdf文件

Exam1. 
A question
Exam2. 
A question
Exam3. 
A question
Exam4. 
A question
Exam5. 
A question

您可以使用任何必要的包,例如:environ,......

答案1

您可以使用environ与此答案中提出的类似的包:https://tex.stackexchange.com/a/181178/118712

本质上,您用空的 替换指定环境的内容{}。您必须\if在每个ex环境之前指定条件命令。我猜您可以尝试使用 将其添加到您的环境定义中newenvironment。您可以使用定理计数器 稍微简化一下\theex

\documentclass{scrartcl}
\usepackage{environ}
\newtheorem{ex}{Exam}
\makeatletter
\providecommand{\env@ex@save@env}{}
\providecommand{\env@ex@process}{}
\makeatother

\def\cond{3}
\newcommand{\condition}{\ifnum\cond=\theex\RenewEnviron{ex}[1]{}\fi}

\begin{document}
    \condition
    \begin{ex}
        \item item
    \end{ex}

    \condition
    \begin{ex}
        \item another item
    \end{ex}

    \condition
    \begin{ex}
        \item another item
    \end{ex}
    
    \condition
    \begin{ex}
        \item another item
    \end{ex}

    \condition
    \begin{ex}
        \item another item
    \end{ex}
\end{document}

相关内容