以下是TeX文件的代码。
\documentclass{exam}
\begin{document}
\begin{questions}
\question Sample Question
\begin{choices}
\choice choice 1
\choice choice 2
\choice choice 3
\choice choice 4
\end{choices}
\end{questions}
\end{document}
是否可以使用 make4ht 或 htlatex 或 lua 代码或任何其他方法来生成每个问题和每个选项的 jpg 图像(因此上述 tex 文件中的示例问题将生成五张图像:一张用于问题,另一张用于四个选项。)jpg 文件不应包含问题编号和选项标签。最后,图像将命名为1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg
问题 1 及其四个选项。第二个问题将有五张图像命名为6.jpg, 7.jpg, 8.jpg, 9.jpg, 10.jpg
等等。
答案1
尝试这个配置文件:
\Preamble{xhtml}
% this counter will be used for picture numbering
\newcount\choicespic
% configure pictures to be .jpg
\Configure{Picture}{.jpg}
\def\setupnextpicture{%
\global\advance\choicespic by 1%
\NextPictureFile{\the\choicespic}%
}
% configure markup and images for the choices environemnt
\ConfigureList{choices}
{\let\origchoice\choice\HCode{</div>}\def\choiceend{}}%
{\choiceend\let\choice\origchoice}
{%
\choiceend\HCode{<div class="choice">}%
\def\choiceend{\HCode{</div>}}%
% update image name
}
{
\setupnextpicture% declare new picture name
\Picture*{}% start picture
\def\choice{\EndPicture\origchoice}% close picture before every \choice command
}
% close picture at end of the choices environment
\AtEndEnvironment{choices}{\EndPicture}
% close \question picture
\BeforeBeginEnvironment{choices}{\EndPicture}
\makeatletter
% save original version of questions environemtn
\let\orig@questions\questions
% redefine the \process@question command to start the picture
\def\questions{%
\orig@questions% execute the original code
\let\origprocessquestion\process@question % save \process@question
\def\process@question{\origprocessquestion\setupnextpicture\Picture*{}}%
}
\makeatother
\ConfigureList{questions}
{%
\def\questionlistend{} % reset questionlistend
\AnchorLabel\SkipRefstepAnchor% remove link inserted by \label
\Configure{()}{$}{$}% disable pictures for math
}
{\questionlistend}
{%
\ifvmode\IgnorePar\fi\EndP\questionlistend%
\HCode{<div class="question"><div class="questiontitle">}%
\def\questionlistend{\HCode{</div>}%
\AnchorLabel\SkipRefstepAnchor%
}
}
{}%{\setupnextpicture\Picture*{}}
\AtEndEnvironment{questions}{\HCode{</div>}}
\begin{document}
\EndPreamble
该类的问题exam
在于它定义了一些仅在环境内有效的命令,因此修补它们非常困难。
使用编译
make4ht -c config.cfg exam.tex
结果如下:
和 HTML:
<div class='questions'>
<a id='x1-3x1'></a><div class='question'><div class='questiontitle'>
1. <img alt='Sample Question ' src='1.jpg' />
</div><div class='choice'>
A. <img alt='choice 1 ' src='2.jpg' />
</div><div class='choice'>
B. <img alt='choice 2 ' src='3.jpg' />
</div><div class='choice'>
C. <img alt='choice 3 ' src='4.jpg' />
</div><div class='choice'>
D. <img alt='choice 4 ' src='5.jpg' /></div>
2. <img alt='Second Question ' src='6.jpg' />
</div><div class='choice'>
<a id='x1-82'></a>A. <img alt='choice 5 ' src='7.jpg' />
</div><div class='choice'>
B. <img alt='choice 6 ' src='8.jpg' />
</div><div class='choice'>
C. <img alt='choice 7 ' src='9.jpg' />
</div><div class='choice'>
D. <img alt='choice 8 ' src='10.jpg' /></div>
</div>