다양한 환경의 여러 위치에 텍스트가 중복됩니까(lslisting?)?

다양한 환경의 여러 위치에 텍스트가 중복됩니까(lslisting?)?

여러분---

질문이 있는데 어떻게 해결해야 할지 모르겠습니다. LaTeX를 사용하는 다른 교사들과 공유하고 싶은 시험 문제 요약을 하나의 PDF로 정리했습니다. 중요한 점은 LaTeX가 아름다운 PDF를 내놓는 동안 다른 사람이 내 문제를 사용하려는 경우 PDF에서 다른 TeX 파일로 복사/붙여넣기가 매우 어려울 수 있다는 것입니다. 물론 각 문제에 대한 소스 코드를 작은 문제 파일로 제공하겠지만 특정 문제를 찾기 위해 전체 폴더나 단일 파일을 파헤치는 것은 약간의 고통이 될 수 있습니다.

나도 알아요---이것들은 가치가 없을 만큼 작은 불만처럼 보이며 대부분 게으름의 산물입니다. 그러나 문제가 해결될 수 있다면 다른 사람들과 함께 이 작업을 수행할 때 오류가 덜 발생하고 향후 문제를 검토, 복사 및 수정하는 것이 좀 더 원활해질 것입니다.

내가 바라는 것은 다음과 같은 일을 할 수 있는 것입니다.

\documentclass[options]{exam}

\usepackage{graphicx}
\usepackage{tikz}
\tikzlibrary{blahblah}
\usepackage{listings}
\usepackages{any other necessary packages to make this work}

\begin{document}

\begin{questions}

\some-command-to-duplicate-question,but-in-a-lstlistings-sort-of-environment{%
\question A question?

\begin{solution}
The solution
\end{solution}
}

\same-command-as-before{%
\includegraphics{diagramforquestion}%could also be for Tikz drawings, tables, other figures, etc

\question Another question?

\begin{solution}
Another solution.
\end{solution}
}

\end{questions}

\end{document}

그렇게 하면 PDF에는 다음과 같은 내용이 있을 것입니다.

  • LaTeX에 의해 적절하게 조판된 다이어그램/등이 포함된 질문 목록;

  • 해당 문제에 대한 소스 코드를 보여주는 일부 목록 목록 또는 유사한 환경.

분명히, 질문의 텍스트를 목록 환경에 복사/붙여넣기만 하면 되지만, 변경사항이 있는 경우 저와 협력하여 질문을 변경하는 사람(또는 아마도 저)이 복사해야 한다는 것을 기억해야 합니다. 모든 변경 사항을 두 번째 환경에 적용하는 반면, 일부 명령을 실행하거나 이 개요서에 대한 일부 환경을 재정의하는 방법이 있다면 조판할 것입니다.그리고쉽게 복사할 수 있도록 소스 코드를 출력하고 한 곳만 수정하면 개별 문제 파일이 훨씬 더 깨끗해지고 시간이 지남에 따라 유지 관리가 더 쉬워집니다.

여러분 모두가 제공할 수 있는 도움에 감사드립니다!

답변1

input와 둘 다 lstinputlisting여기 당신의 친구입니다.

솔루션용 파일도 포함하도록 명령을 수정할 수 있습니다 \question. 유일한 것은 \input유효한 TeX이어야 하므로 사용되는 경우입니다.

\documentclass[10pt]{article}

\usepackage{graphicx}
\usepackage{tikz}
\usepackage{listings}
\lstset{basicstyle=\footnotesize\ttfamily,breaklines=true}

\newcommand{\question}[4]{
    #1

    The question is

    \begin{center}
        \input{#2}
    \end{center}

    For copy-pasting, the question is

    \lstinputlisting{#2}

    The solution is here:
    \begin{center}
        #3
    \end{center}

    #4
}

\begin{document}

Introduction

\begin{enumerate}
    \item \question{For undergraduates:}{q1}{My solution}{
        A figure to help explain

        \begin{tikzpicture}
        \draw (0,0) -- (2,0) -- (2,2) -- (0,0);
        \end{tikzpicture}
    }
    \item \question{For grad students:}{q1}{Another solution}{No figure needed for grad students}
\end{enumerate}


\end{document}

이것을 진정한 MWE로 만들기 위해 q1.tex동일한 디렉터리에 다음과 같은 파일이 있습니다.

If $n = 3$, $x^n + y^n = z^n$ has no integer solutions. If you have extra time, please prove this for all other $n > 2$.

관련 정보