定义可以为不同版本打开和关闭的环境

定义可以为不同版本打开和关闭的环境

我想用 LaTeX 为我的课程创建一份详细的课程指南,其中列出了每节课的详细课程目标。我还想使用同一文档嵌入教学笔记。这样,我便拥有一份文档,它既是发给学生的课程指南,也是教师可以用来授课的教学指南。

我想定义一个环境,使教学内容可以“打开”并可见。但我也可以将其关闭,其余文本将成为学生的课程指南。这将类似于考试课程,您可以在其中显示或不显示答案,通过文档类行上的选项进行控制。我不想发明整个文档类,只是想要一个只需在顶部一行即可打开教师版的东西。

我知道如何定义环境,但是有没有办法从顶部的一行全局打开/关闭它?

答案1

在评论你的问题/其他答案时使用评论包裹已经建议了。

使用文档条包裹可能采取一种不同的、非基于环境的方法来处理这一问题。

文档条包裹是一种从一个(一组)主文件派生出不同 .tex 输入文件的方法。在主文件中,您可以放置​​所谓的标签。这些标签用于确定主文件中标记的文本部分将被复制到哪些派生文件。

在主文件的头部和另一个文件中,您都可以使用所谓的\generate指令来创建从主文件派生的文件。

有关更多信息文档条可以在 CTAN 找到此包。

如果将以下示例保存为文件,并且文件名不是老师.tex并且除此以外学生.tex并使用特克斯或者pdftex或者乳胶或者pdflatex,将创建两个新文件,其中一个名为老师.tex,另一个叫做学生.tex

%<*ignore>
% Section with docstrip directives for generating different 
% .tex-input-files:
\input docstrip

\declarepreamble\teachers
____________________________

Course Guide, release only for teachers, with teaching notes embedded.

Use pdflatex/pdftexify for compiling this file.

\endpreamble

\declarepreamble\students
____________________________

Course Guide, release for students, no teaching notes embedded.

Use pdflatex/pdftexify for compiling this file.

\endpreamble

\generate{%
  \nopostamble
%
  \usepreamble\teachers
  \file{teacher.tex}{\from{\jobname.tex}{teacher}}%
%
  \usepreamble\students
  \file{students.tex}{\from{\jobname.tex}{students}}%
}%
% Here you can probably insert \write18-calls suitable for your platform
% for calling pdflatex from console for compiling the files
% just generated -- something like:
%    \immediate\write18{pdflatex teacher.tex}
%    \immediate\write18{pdflatex students.tex}
%    \immediate\write18{pdftexify teacher.tex}
%    \immediate\write18{pdftexify students.tex}
%
\csname stop\endcsname % <- end this TeX-run in case you used (pdf)LaTeX
                       %    for generating the files.
%
\bye % <- end this TeX-run in case you used (pdf)TeX for generating the 
%    %    files.
%
%</ignore>
% Section containing the actual LaTeX document, with tags for
% generating different variants with different target groups
%<*teacher,students>
\documentclass{article}
\begin{document}
This is both for students and for teachers.
%<*teacher>
This is for teachers only.
%</teacher>
%<*students>
This is for students only.
%</students>
This is both for students and for teachers also.
\end{document}
%</teacher,students>

的内容老师.tex将:

%%
%% This is file `teacher.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% test.tex  (with options: `teacher')
%% ____________________________
%% 
%% Course Guide, release only for teachers, with teaching notes embedded.
%% 
%% Use pdflatex/pdftexify for compiling this file.
%% 
\documentclass{article}
\begin{document}
This is both for students and for teachers.
This is for teachers only.
This is both for students and for teachers also.
\end{document}

的内容学生.tex将:

%%
%% This is file `students.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% test.tex  (with options: `students')
%% ____________________________
%% 
%% Course Guide, release for students, no teaching notes embedded.
%% 
%% Use pdflatex/pdftexify for compiling this file.
%% 
\documentclass{article}
\begin{document}
This is both for students and for teachers.
This is for students only.
This is both for students and for teachers also.
\end{document}

相关内容