我知道这不是排版问题,但如果有人能帮我指向一个网站,那个网站可以帮助或建议我需要学习什么类型的语言才能做我想做的事情......我想设置下面的页面一次打印出 20 个随机页面,而不用在 20 个不同的页面上复制文件或每次运行时都按打印。
\documentclass{article}
%AdditionCode
\usepackage{tikz}
\pgfmathsetseed{\number\randomseed}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{xlop}
\usepackage{pstricks}
\usepackage{pgfmath}
\usepackage{pgf}
% \usepackage{showframe}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{~\\56 Problem Practice Worksheet}
\rhead{Name: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \\}
\lfoot{Number Correct: ~ \Large $\dfrac{~}{20}$}
\cfoot{~}
\newcommand*{\DifficultyOne}{999}%
\newcommand*{\DifficultyTwo}{99}%
%---------------------------------------%
\newcommand{\AddQuestion}[1]{%
\foreach \i in {1,...,#1}{%
\pgfmathtruncatemacro{\AddOnea}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwoa}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOneb}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwob}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOnec}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwoc}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOned}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwod}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOnee}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwoe}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOnef}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwof}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOneg}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwog}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOneh}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwoh}{random(\DifficultyTwo)}
\hspace*{\fill}
\opadd[carryadd=true, voperator=bottom, resultstyle=\white]{\AddOnea}{\AddTwoa} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\white] {\AddOneb}{\AddTwob} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\white]{\AddOnec}{\AddTwoc} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\white] {\AddOned}{\AddTwod} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\white]{\AddOnee}{\AddTwoe} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\white]{\AddOnef}{\AddTwof} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\white]{\AddOneg}{\AddTwog} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\white]{\AddOneh}{\AddTwoh} \hspace*{\fill}\\
~\newline
~\newline
}%
}%
%\pgfmathsetseed{\number\randomseed}
\begin{document}
\vspace{2cm}
\AddQuestion{5}
\end{document}
答案1
以下脚本适用于zsh
和bash
,它们是 macOS 中常用的两个 shell。它假定使用 XeLaTeX 进行编译(因为pstricks
),并且需要安装 (Ghostscript)。我相信 Ghostscript 是由 TeX Live/MacTeX 安装的,但如果没有,您可以从 Mac 终端gs
安装它。brew install gs
脚本:
for i in {1..20}
do
xelatex practiseworksheet.tex
mv practiseworksheet.pdf worksheetcopy$i.pdf
done
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=exercise20.pdf worksheetcopy*.pdf
该脚本运行 XeLaTeX 20 次,每次将输出复制到一个编号文件,最后将所有 20 个文件合并到一个exercise20.pdf
可以正常打印的文件中。
但是,XeLaTeX 每分钟只更新一次随机种子。这意味着所有练习表可能都相同(因为通常在一分钟内会完成 20 次运行)。要修改此行为,您可以在 LaTeX 代码中将随机种子明确设置为值\randomseed
,每次运行该值都不同。相关代码:
\usepackage{tikz}
\pgfmathsetseed{\number\randomseed}
一步一步的说明:
- 将脚本代码复制到 TextEdit 等文本编辑器中。
- 确保 LaTeX 文件的文件名与脚本第 3 行和第 4 行中的名称相对应。如有必要,请更改它。例如,如果调用了您的 LaTeX 文件,
myfile.tex
则脚本中的行需要为:xelatex myfile.tex mv myfile.pdf worksheetcopy$i.pdf
- 将 TextEdit 中的脚本保存在与 LaTeX 文件相同的目录中。例如,选择作为脚本文件的文件名
exercise20.sh
。 - 打开一个终端。
- 使用
cd
。例如,如果您的 LaTeX 文件位于目录中练习这是我的项目在你的主目录中,然后输入cd "My Projects/Exercises"
。 - 通过输入 确认您处于正确的目录中
ls
。这将列出当前目录中的所有文件。检查您的 LaTeX 文件是否已列出。如果没有,则需要使用其他cd
命令。还要确认脚本文件是否位于该目录中(名称为exercise20.sh
)。 - 现在,仍然在终端中输入
zsh exercise20.sh
。为了清楚起见:不要直接在终端中输入或复制脚本。 - 脚本将运行,并显示 LaTeX 的输出。
- 脚本运行完成后,打开 Finder 并转到目录。
- 找到该文件
exercise20.pdf
,打开并打印。
下面显示了使用 pdflatex 而不是 xelatex 的替代版本。此版本\usepackage{pstricks}
已被删除。PSTricks 仅用于颜色规范,例如\white
,可以用不需要 PSTricks 的更标准版本替换。这样就可以使用 pdflatex 进行编译。在这种情况下,您需要使用\color{white}
而不是。\randomseed
\pdfrandomseed
文档:
\documentclass{article}
%AdditionCode
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{tikz}
\pgfmathsetseed{\number\pdfrandomseed}
\usepackage{xlop}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{~\\56 Problem Practice Worksheet}
\rhead{Name: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \\}
\lfoot{Number Correct: ~ \Large $\dfrac{~}{20}$}
\cfoot{~}
\newcommand*{\DifficultyOne}{999}%
\newcommand*{\DifficultyTwo}{99}%
%---------------------------------------%
\newcommand{\AddQuestion}[1]{%
\foreach \i in {1,...,#1}{%
\pgfmathtruncatemacro{\AddOnea}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwoa}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOneb}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwob}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOnec}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwoc}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOned}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwod}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOnee}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwoe}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOnef}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwof}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOneg}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwog}{random(\DifficultyTwo)}
\pgfmathtruncatemacro{\AddOneh}{random(\DifficultyOne)}%
\pgfmathtruncatemacro{\AddTwoh}{random(\DifficultyTwo)}
\hspace*{\fill}
\opadd[carryadd=true, voperator=bottom, resultstyle=\color{white}]{\AddOnea} {\AddTwoa} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\color{white}]{\AddOneb}{\AddTwob} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\color{white}]{\AddOnec}{\AddTwoc} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\color{white}]{\AddOned}{\AddTwod} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\color{white}]{\AddOnee}{\AddTwoe} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\color{white}]{\AddOnef}{\AddTwof} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\color{white}]{\AddOneg}{\AddTwog} \hfill \opadd[carryadd=true, voperator=bottom, resultstyle=\color{white}]{\AddOneh}{\AddTwoh} \hspace*{\fill}\\
~\newline
~\newline
}%
}%
\begin{document}
\vspace{2cm}
\AddQuestion{5}
\end{document}
脚本:
for i in {1..20}
do
pdflatex practiseworksheet.tex
mv practiseworksheet.pdf worksheetcopy$i.pdf
done
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=exercise20.pdf worksheetcopy*.pdf