2

I created a class which adapts the exam class to the needs of my school and added some stuff to control the class from the outside by a script to be able to create an individual exam for each student with the name and additional information printed on it. All this is controlled by an external bash script. I use something like pdflatex "\newcommand\examstudentname{somestudent} \newcommand\externalwithanswers{no}" the_exam.tex from inside the bash script to generate the exam pdf. As in the the_exam.tex file it might happen that the option [answers] was set accidentally, an exam with answers included might be created (Actually, something like that once happened at our school). To have complete control I need the script to set and unset options like [answers] of the class I inherited from (exam.cls).

Case 1: My the_exam.tex might have:

\documentclass{HTWChurExam} 

HTWChurExam.cls has something like:

\PassOptionsToClass{answers}{exam} 

This deliberately turns on [answers] for exam.cls. No problem, settled. Easy to control from outside by a script.

Case 2: My the_exam.tex might have:

\documentclass[answers]{HTWChurExam} 

HTWChurExam.cls has something like:

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{exam}} 

which will pass all options down to exam.cls. I now want to have the possibility to deliberately turn off [answers], controlled by a bash script.

I haven't found any way to accomplish this.

4
  • In general, a *.cls file uses \DeclareOption to define other commands, or set flags true or false. Look at the *.cls code, to see what is defined and set. The actual effect may not happen until later, perhaps when the document body begins. If that is true, can you re-define the commands, or re-set the flags, \AtBeginDocument ? Commented Jan 26, 2017 at 20:48
  • Thanks for trying to answer. The question seemed not to be clear enough. So I edited quite heavily. Commented Jan 26, 2017 at 21:14
  • Ah, after the edits, I see. My above suggestion would not work for you. Commented Jan 26, 2017 at 21:25
  • I can see two possibilities. 1. Have your bash script copy the tex file before processing, adding the line \PassOptionsToClass{noanswers}{exam}. 2. Have the script run pdflatex, or equivalent, using pdflatex -jobname=myexam "\PassOptionsToClass{noanswers}{exam}\input{realexam}". In both cases you probably want have your script then copy the pdf to the expected filename. Commented Jan 26, 2017 at 22:52

1 Answer 1

1

My solution is:

\providecommand{\externalwithanswers}{}% fallback definition \newcommand{\withname}{yes} \newcommand{\withscoretable}{yes} \newcommand{\withpagescore}{yes} \newcommand{\withanswers}{} \newcommand{\withanswersnewpage}{} \newcommand{\noanswersnewpage}{\newpage} \newcommand{\withanswerslinebreak}{} \newcommand{\useanswers}% {%use answers \typeout{HTWChurExam class: using answers} \renewcommand{\withanswers}{(mit Anworten)}% \renewcommand{\withanswersnewpage}{\newpage} % \renewcommand{\noanswersnewpage}{} % \renewcommand{\withanswerslinebreak}{\linebreak} % } \newcommand{\usenoanswers}% {%do not use answers \typeout{HTWChurExam class: not using answers} \renewcommand{\withanswers}{} \renewcommand{\withanswersnewpage}{} \renewcommand{\noanswersnewpage}{\newpage} \renewcommand{\withanswerslinebreak}{} } \typeout{HTWChurExam class: default answer display} \usenoanswers \DeclareOption*{\PassOptionsToClass{\CurrentOption}{exam}} \DeclareOption{answers}% {% \typeout{\currfilebase: using answers requested} %test if external script call supersedes using answers with 'no' option \ifthenelse{\equal{no}{\externalwithanswers}} % {%if external answerdefinition is 'no' \typeout{HTWChurExam class: external scipt call -> using no answers} }% {%if external answerdefinition is not 'no' \PassOptionsToClass{answers}{exam} \useanswers }% } %test for external withanswer 'yes' option \ifthenelse{\equal{yes}{\externalwithanswers}} % { %if external answerdefinition is 'yes' \typeout{HTWChurExam class: external scipt call -> using answers} \PassOptionsToClass{answers}{exam} \useanswers } % {}% 

The key is to pass the option answer to the class exam only when it is sure from all conditions combined that the answers are really required to be displayed. Thank you anyway for helping me out as it kind of triggered my solution.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.