From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id gBDSAdg7W2CpXgAA0tVLHw (envelope-from ) for ; Wed, 24 Mar 2021 13:17:12 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id OGEyOdc7W2AgPwAAB5/wlQ (envelope-from ) for ; Wed, 24 Mar 2021 13:17:11 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 0A0BB12726 for ; Wed, 24 Mar 2021 14:17:11 +0100 (CET) Received: from localhost ([::1]:34144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lP3Nl-00069g-80 for larch@yhetil.org; Wed, 24 Mar 2021 09:17:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lP3NK-00069Z-4a for emacs-orgmode@gnu.org; Wed, 24 Mar 2021 09:16:42 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:40818) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lP3NH-0005JF-Lu for emacs-orgmode@gnu.org; Wed, 24 Mar 2021 09:16:41 -0400 Received: by mail-wr1-x431.google.com with SMTP id v11so24399359wro.7 for ; Wed, 24 Mar 2021 06:16:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zzamboni-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZhgTMrqS3jkdCggy58AsCwztkALOk5MDOr6O64nfQ38=; b=GRBrLPE+j0uwutuB8bmYuQmtnX9fX4ibNghYbA4R6q7fCnpqjsWx+PTaVg0ycoPwYg fN3hrK4EyIaVA2EMEgyzwUZQh0RFpBXrqLM3mLxOnNUyOJLHq4ZPSItimEVqxO4QeJG5 mUzRi6t+Ea9nybJIbt11QueMM/k0rjMg3ShCYMRbOIyNPCa3pHk5Is+eKvU5MKculQzh YijGpEe5DFKUFomNctnQANEDN+lW0h1dSMyNWGCzcAgzgMVAszs25I4cBvRtdNaXQoso Eb5PmEyBd3UjnMSu8GRYUo2fpSXDj08xRH8jpF27b8Gmr+rOuvFdfc58LITVcqupAwUI XoqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZhgTMrqS3jkdCggy58AsCwztkALOk5MDOr6O64nfQ38=; b=o2uNkyP6DIVXzrNFJSYVSfUGiW8t3s2HoEBPALLj526xzSNM4xnQ6zBvYbpheKhETX gcnoU05fNIAT9va7OwYYhS8mtIOWpIaGHJ+9zOC/YUXHFtN7DYZNmFtBgdxapdBlniPH 58lwvRUvGaGUPNRoQgp0Zu91i8PuiwdKpSMbMKMM89eAEVjJxjPBZX0pT+EBA0SEDF2n j/qnIaCc3QaTvn/0GuZgr269SztXiXQebIQZF2XhCMOs6Vt16Y5pfAx1nIA7pGFAYOau QwlepLKjqSY4T39dOQGsYurKJ9S2gwr/IAbSQNajP5RMEROfaHPZoOCDI+gdEq/fWq3o HjIQ== X-Gm-Message-State: AOAM5331fe4yU7YhvDNNL2NsliH4FwM3O6yHkRGukOGVQ+9YwEPMZSsR 7B+L7ZXtgymCC1LlgePAmr46cu7mMZ05C9xCXTIloA== X-Google-Smtp-Source: ABdhPJw9cAmlLnzpG+KwV2JBTE7u5fYeGBhAKXTG2yzkS2w/Ld4gS/kDoOc+VXTTkisBj+u/8qkkkytVsv0V1Wb1Mno= X-Received: by 2002:adf:edc3:: with SMTP id v3mr3361785wro.79.1616591797397; Wed, 24 Mar 2021 06:16:37 -0700 (PDT) MIME-Version: 1.0 References: <87pmzvo3i4.fsf@chark.eu> <43d0c2349e6a4345f7f100b13244c0a6@gmail.com> In-Reply-To: <43d0c2349e6a4345f7f100b13244c0a6@gmail.com> From: Diego Zamboni Date: Wed, 24 Mar 2021 14:16:26 +0100 Message-ID: Subject: Re: Exam LaTeX class To: =?UTF-8?B?WGlhbndlbiBDaGVuICjpmYjotKTmlocp?= Content-Type: multipart/alternative; boundary="000000000000d4c23505be481b2f" Received-SPF: none client-ip=2a00:1450:4864:20::431; envelope-from=diego@zzamboni.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Org-mode , =?UTF-8?Q?Christine_K=C3=B6hn?= Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1616591831; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=ZhgTMrqS3jkdCggy58AsCwztkALOk5MDOr6O64nfQ38=; b=fuoLtKFTvGf1ZMdp2bHe3cek21OnAWBZOR023t8oqTqOgVX0b5B7rnz4a4m0Hl1GJnswQT a1nRX9eEIlwvLlRgl8Vd/7ocdLnS8wq1fS9Hqa6jiHWjdNZsMSgVuq8RUGJ0XXCUmlxovf JeVtDywnorbrRC+hfBVhWnlc+aKic4qFKDULZobLrSzJAW1uTDH/iSCXhfMl4At+zQCgA6 wWPjh24s21os4slyWBiQj7QgdufiDVaOo0PwU9CgJAIlGsBwq96QDXJdzUhoxng1kBulCE W/jq0zxSNQbk2svevPLLywERzbT+fNE4ifItQ4sF+szN9UyU+S74xxvROPoX0w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1616591831; a=rsa-sha256; cv=none; b=Oz7YAeQZ5JidQFOd+DZ3a8aMkoLTq9xh+T3T6YVIl/995o4gFHccw313blhNPruhs8j87B UodrTbhiNjgI0Y1NM7kweWCytzDJ3eThgkXKh5ocBhrk/BDkbfMKAd8Yxhbw1iySd73vrF lvNE01FAsFIl0WqjKZvLM2gqwYh/EndacKtnGYkK2R3L5rHh0Zfn98h6TIoeJ6hSMRb/h9 VKgqLo9DT4+vnlkWGyGxJDsdUPv0uc817GM0xSf6Q7/j+HHhtgjsqePQURMFG8qXg1ZNS3 yGRkIE7dYxv6dDyc/5tdS2jgvs2LWgV+5T9+6OqHXKr6rSx+TJnMD4LUbjaBwQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=zzamboni-org.20150623.gappssmtp.com header.s=20150623 header.b=GRBrLPE+; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -1.97 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=zzamboni-org.20150623.gappssmtp.com header.s=20150623 header.b=GRBrLPE+; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 0A0BB12726 X-Spam-Score: -1.97 X-Migadu-Scanner: scn0.migadu.com X-TUID: hQ1FlifByedM --000000000000d4c23505be481b2f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Xianwen, 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: #+include: ./printanswers.org #+TITLE: Test ... 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 () (interactive) (write-region "#+latex_header: \\printanswers" nil "printanswers.org") (org-latex-export-to-pdf) (rename-file (org-export-output-file-name ".pdf") (org-export-output-file-name "-with_answers.pdf")) (write-region "" nil "printanswers.org") (org-latex-export-to-pdf)) You can then run M-x org-latex-export-exams to generate both files. Hope this helps, --Diego On Wed, Mar 24, 2021 at 11:21 AM Xianwen Chen (=E9=99=88=E8=B4=A4=E6=96=87)= wrote: > Dear Christine (and CC list), > > Thank you! > > > > On 2021-03-19 10:13, Christine K=C3=B6hn wrote: > > Here is one way to do the latex part. You could pass a jobname to latex. > > I have this > > \IfEndWith*{\jobname}{withsolution}{% > \usepackage{todonotes} > \printanswers > }{\usepackage[disable]{todonotes}} > > in a myexam.sty file to switch between modes (with or without solutions > and todo notes) and use it in the latex file with > > \usepackage{myexam} > > 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=3D"pdflatex --interaction=3Derrorstopmode" -use-ma= ke > > and adds -jobname=3D$(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 ye= t. > > (deffun org-latex-export-to-pdf-exam () > (interactive) > # do some emacs lisp to add \printanswers to the end of org document > header, i.e., adding a line of #+LATEX_HEADER: \printanswers > (org-latex-export-to-pdf) > # 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 addi= ng > a line of #+LATEX_HEADER: \noprintanswers > (org-latex-export-to-pdf) > # 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 wit= h > solutions and one without. > > What do you think? > > Yours sincerely, > Xianwen > --000000000000d4c23505be481b2f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Xianwen,

I think the easiest way to = conditionally include text in the preamble of the document would be by incl= uding a file which can be empty sometimes, and contain the appropriate=C2= =A0text when needed. For example, you could have something like this in you= r Org file:

#+include: ./= printanswers.org
#+TITLE: Test
...

Then the following function will automatically export= the file twice, one with the \printanswers command inserted then rename th= e resulting file, and export again without:

(defun org-latex-= export-exams ()
=C2=A0 (interactive)
=C2=A0 (write-regi= on "#+latex_header: \\printanswers" nil "printanswers.org")
=C2=A0 (org-latex-ex= port-to-pdf)
=C2=A0 (rename-file (org-export-output-file-name &qu= ot;.pdf") (org-export-output-file-name "-with_answers.pdf"))=
=C2=A0 (write-region "" nil "printanswers.org")
=C2=A0 (org-latex-exp= ort-to-pdf))

You can then run M-x org= -latex-export-exams to generate both files.

Hope t= his helps,
--Diego


On Wed, Mar 24, 2021 at 11= :21 AM Xianwen Chen (=E9=99=88=E8=B4=A4=E6=96=87) <xianwen.chen@gmail.com> wrote:

Dear Christine (and CC list),

Thank you!

=C2=A0


On 2021-03-19 10:13, Chr= istine K=C3=B6hn wrote:

Here is one way= to do the latex part. You could pass a jobname to latex.

I have thi= s

\IfEndWith*{\jobname}{withsolution}{%
=C2=A0=C2=A0\usepackage{t= odonotes}
=C2=A0=C2=A0\printanswers
}{\usepackage[disable]{todonotes}= }

in a myexam.sty file to switch between modes (with or without solu= tions
and todo notes) and use it in the latex file with

\usepacka= ge{myexam}

You could add your own latex class to org-latex-classes a= nd add this
line there.

The jobname has to be passed to latex wit= h something like -jobname
withsolution if you want it to be with solutio= ns. I use a Makefile for
this purpose which calls latexmk

latexmk= -pdf -pdflatex=3D"pdflatex --interaction=3Derrorstopmode" -use-m= ake

and adds -jobname=3D$(basename $@) if asked to create a pdf endi= ng with
withsolution.pdf. I can send you the Makefile if you're inte= rested.
=C2=A0
That's very= interesting way to solve the problem using LaTeX. Thank you for sharing th= is. At the moment I'm leaning more towards solving it using emacs lisp.=
=C2=A0
To use the jobn= ame 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).
=C2=A0
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.
=C2=A0
(deffun org-lat= ex-export-to-pdf-exam ()
=C2=A0 (interac= tive)
=C2=A0 # do som= e emacs lisp to add \printanswers to the end of org document header, i.e., = adding a line of #+LATEX_HEADER: \printanswers
=C2=A0 (org-lat= ex-export-to-pdf)
=C2=A0 # do som= e emacs lips to move the foo.pdf to foo-with_solutions.pdf
=C2=A0 # do som= e 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
=C2=A0 (org-lat= ex-export-to-pdf)
=C2=A0 # remove= the line of #+LATEX_HEADER: \noprintanswers
)
=C2=A0
I don't kno= w enough emacs lisp to fill in the details here for now. However, I think t= his would be a way to do it within emacs. So each time I call org-latex-exp= ort-to-pdf-exam, it would export two PDF files, one with solutions and one = without.
=C2=A0
What do you thi= nk?
=C2=A0
Yours sincerely= ,
Xianwen
--000000000000d4c23505be481b2f--