From: Diego Zamboni <firstname.lastname@example.org>
To: "Xianwen Chen (陈贤文)" <email@example.com>
Cc: Org-mode <firstname.lastname@example.org>, "Christine Köhn" <email@example.com>
Subject: Re: Exam LaTeX class
Date: Wed, 24 Mar 2021 14:16:26 +0100 [thread overview]
Message-ID: <CAGY83Efhsk2SL6RTG+j5TUem-srFfo88sPBMvGvHi12mBqXHgw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 3626 bytes --]
I think the easiest way to conditionally include text in the preamble of
the document would be by including a file which can be empty sometimes, and
contain the appropriate text when needed. For example, you could have
something like this in your Org file:
Then the following function will automatically export the file twice, one
with the \printanswers command inserted then rename the resulting file, and
export again without:
(defun org-latex-export-exams ()
(write-region "#+latex_header: \\printanswers" nil "printanswers.org")
(rename-file (org-export-output-file-name ".pdf")
(write-region "" nil "printanswers.org")
You can then run M-x org-latex-export-exams to generate both files.
Hope this helps,
On Wed, Mar 24, 2021 at 11:21 AM Xianwen Chen (陈贤文) <firstname.lastname@example.org>
> Dear Christine (and CC list),
> Thank you!
> On 2021-03-19 10:13, Christine Köhn wrote:
> Here is one way to do the latex part. You could pass a jobname to latex.
> I have this
> in a myexam.sty file to switch between modes (with or without solutions
> and todo notes) and use it in the latex file with
> You could add your own latex class to org-latex-classes and add this
> line there.
> The jobname has to be passed to latex with something like -jobname
> withsolution if you want it to be with solutions. I use a Makefile for
> this purpose which calls latexmk
> latexmk -pdf -pdflatex="pdflatex --interaction=errorstopmode" -use-make
> and adds -jobname=$(basename $@) if asked to create a pdf ending with
> withsolution.pdf. I can send you the Makefile if you're interested.
> That's very interesting way to solve the problem using LaTeX. Thank you
> for sharing this. At the moment I'm leaning more towards solving it using
> emacs lisp.
> To use the jobname from within orgmode, you'll have to change
> org-latex-pdf-process to use the jobname if needed. I think one way to
> achieve this is to add a new export backend which is derived from latex
> (see org-export-define-derived-backend) and which sets
> org-latex-pdf-process accordingly (and resets it afterwards).
> Thank you again. I'm thinking of a function like following. I'm using
> comments to express the programming detail that I don't know how to do yet.
> (deffun org-latex-export-to-pdf-exam ()
> # do some emacs lisp to add \printanswers to the end of org document
> header, i.e., adding a line of #+LATEX_HEADER: \printanswers
> # do some emacs lips to move the foo.pdf to foo-with_solutions.pdf
> # do some emacs lisp to add \noprintanswers to the end of org document
> header, i.e., removing the line of #+LATEX_HEADER: \printanswers and adding
> a line of #+LATEX_HEADER: \noprintanswers
> # remove the line of #+LATEX_HEADER: \noprintanswers
> I don't know enough emacs lisp to fill in the details here for now.
> However, I think this would be a way to do it within emacs. So each time I
> call org-latex-export-to-pdf-exam, it would export two PDF files, one with
> solutions and one without.
> What do you think?
> Yours sincerely,
[-- Attachment #2: Type: text/html, Size: 6457 bytes --]
next prev parent reply other threads:[~2021-03-24 13:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-18 13:46 Exam LaTeX class Xianwen Chen (陈贤文)
2021-03-19 10:13 ` Christine Köhn
2021-03-24 10:26 ` Xianwen Chen (陈贤文)
2021-03-24 13:16 ` Diego Zamboni [this message]
2021-03-28 16:33 ` Xianwen Chen (陈贤文)
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).