From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id mJ/yAseuYGB/cAEAgWs5BA (envelope-from ) for ; Sun, 28 Mar 2021 18:28:55 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id oNxtOMauYGAJEQAA1q6Kng (envelope-from ) for ; Sun, 28 Mar 2021 16:28:54 +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 2D6C51AF7C for ; Sun, 28 Mar 2021 18:28:54 +0200 (CEST) Received: from localhost ([::1]:59074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lQYHU-000088-Qv for larch@yhetil.org; Sun, 28 Mar 2021 12:28:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQYH1-000080-CW for emacs-orgmode@gnu.org; Sun, 28 Mar 2021 12:28:23 -0400 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]:35410) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lQYGw-0007xR-1Y for emacs-orgmode@gnu.org; Sun, 28 Mar 2021 12:28:23 -0400 Received: by mail-lj1-x232.google.com with SMTP id a1so13235587ljp.2 for ; Sun, 28 Mar 2021 09:28:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:date:from:to:cc:subject:in-reply-to:references :user-agent:message-id; bh=8w4yC3KEHiCcxwuHiL0J5yp3LYKK3A4pQiNuaC/8DTw=; b=KRrVa3jwK8VD3WvxeDlL0fojtj8chZQNANYRxAqqethAweoezJ84evswqVu7PwozBf jmcpI628yOil2sZo/nSIFVZM01cY0T4MJwCrJX3HwDVCoMfPDQIAwrQKWXI181gknDay z7+/cC5ZRcdp3e8BRK4oSbRTKxHSTTXY+pVGz9VnC+JDmYX07bu0kHKZFXiowYwE869u /eHMaTuT5ToBEB+hNxrLAr1nu/Ni2B7EXgIIIIXQvbaUjK4H9BuQZAvuAiGFQxJETXj4 kqbpBGSEpxDkPjVl/mz44j/YOyux9M3s1jQpw+O5NBCj9icy2gTB3ysf8tI6HKbMqo5C CbeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:from:to:cc:subject:in-reply-to :references:user-agent:message-id; bh=8w4yC3KEHiCcxwuHiL0J5yp3LYKK3A4pQiNuaC/8DTw=; b=HyzPdFi+TXNCuEIYTp7pyFVjHfdg+Ry/y4ynkh030OMk050BRnYelI4LSpiLMsaeEG bQIVtXECeOMlNPDoov+7hm2FcFmLaKxmsIKwF5iBOofilCl4xY8s6RRDOntXuX3XSXe8 8YkhbhAIxBVqAdMkrV+36uvOxA9Kpntg8xnVnhsYhro7s+MlT38C3jl/pIZRv9NURbK5 Byi9ZvYLmGAid4QdTXFxTHjrrZhpcybnOufiPpnkQexNaG/A07W1BaTz2LeiYzcfrDjW /+OX9933ayh9agV8zymBWZt7AP2puwZCatNuuo0wzB1AXznm5re6R1Hhd1p6mXAF9PnD K49g== X-Gm-Message-State: AOAM532xxSA5aIm1qVu6MSzOdrue0pOwckejDBV2wxKvxKTJ97Eo/guV S2TZZxEGDregfBA0KRuYrMw= X-Google-Smtp-Source: ABdhPJyDdvnp4zMRIjw0liPe7B4yRfCjd2iT48jRb/fOf2+j7TxiH4GrovqKRM+mtx1YdKxROMv7OA== X-Received: by 2002:a2e:9143:: with SMTP id q3mr9224774ljg.378.1616948895765; Sun, 28 Mar 2021 09:28:15 -0700 (PDT) Received: from m.g.s.chen.ac (cm-84.214.37.174.getinternet.no. [84.214.37.174]) by smtp.gmail.com with ESMTPSA id r66sm1517523lff.93.2021.03.28.09.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 09:28:15 -0700 (PDT) MIME-Version: 1.0 Date: Sun, 28 Mar 2021 16:33:07 +0000 From: =?UTF-8?Q?Xianwen_Chen_=28=E9=99=88=E8=B4=A4=E6=96=87=29?= To: Diego Zamboni Subject: Re: Exam LaTeX class In-Reply-To: References: <87pmzvo3i4.fsf@chark.eu> <43d0c2349e6a4345f7f100b13244c0a6@gmail.com> User-Agent: Roundcube Webmail/1.4.10 Message-ID: <7fe41161285191b284462eefaba02dba@gmail.com> X-Sender: xianwen.chen@gmail.com Content-Type: multipart/alternative; boundary="=_b6855e5285da850ef8fefef7e718999a" Received-SPF: pass client-ip=2a00:1450:4864:20::232; envelope-from=xianwen.chen@gmail.com; helo=mail-lj1-x232.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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=1616948934; 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=8w4yC3KEHiCcxwuHiL0J5yp3LYKK3A4pQiNuaC/8DTw=; b=qGq81adWQ7DM9FFNLWIKJyrV09iFoet5VjwmzQxcQ1+xupw1EzAYQOEfBNGKgWJNGw8yf8 6K/7m28XpY0hkJGhOAVYNAzLvQPVMdpOPyq9UmG5FE2uHwNk6ZEytZwfLmSpx4goOIRrRc jZ7cXT7smCuUNGIkznnkGzCt2VovLNR3FcdghbIarB6AAFTnfYDhyTmxlfEG0bLj1DEd68 Q9DkflW7eKjuL8wC3uf9n2EB1hdtILUDH6eQ+32nGlEczXMulTuS9BJ0NIt3Y/M0s3TZch 1lBp0DQKosQOSALXKClIV3sxvnKyO7lUhwXRVlcA8KnGxixnjW+F3U6M97avBA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1616948934; a=rsa-sha256; cv=none; b=T2WbAGQym6GNwZOs+7MFOujaATXIVU1ZIvra4xfBhowRIHRHiTubtOJ36sjpeIs5yyP2lh WLPBoR6YYlgbiR0e0C929atCNgDyf2yA1UCYq4pSXRyNHf7f5lBY+exRduwL/BikA1Pi0I ZRUUxrghdRvMizOUZiL9NCGEhVdj055KK6q15hxdZLdyBsWqducIrKZZP6FvK/uQFsY5Kq UWlu2BBb400ipzCwtZGiaiCFE5Z7ltlMeK1u2O9loxX1WnmknJJjFZlFiF38gABYBNRsJC bJVkXt0CrQKyEftqyZpHfjLRxDucmqQmJ7p25ekHOdEPhO84bRi5+k+i8oJQ9A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20161025 header.b=KRrVa3jw; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=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-Spam-Score: 0.18 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20161025 header.b=KRrVa3jw; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=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: 2D6C51AF7C X-Spam-Score: 0.18 X-Migadu-Scanner: scn0.migadu.com X-TUID: syVhyIKIudTM --=_b6855e5285da850ef8fefef7e718999a Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8; format=flowed Dear Diego, Gracias! I slightly modified your solution. I added the #+INCLUDE line to the end of #+LATEX_HEADER, because then it will overwrite any previous \printanswers and \noprintanswers defined in the HEADER. #+TITLE:... ... #+LATEX_HEADER: \usepackage{hyperref} #+INCLUDE: ./latex-exam-printanswers-switch.org I used the file name latex-exam-printanswers-switch.org, instead of printanswers.org, because it gives a better indication of what it does. I used your function as it was, except that I changed the function name and updated the switch org file. (defun org-latex-export-to-pdf-exam () (interactive) (write-region "#+LATEX_HEADER: \\printanswers" nil "latex-exam-printanswers-switch.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 "latex-exam-printanswers-switch.org") (org-latex-export-to-pdf) ) It works very fine! Have a nice Easter! Yours sincerely, Xianwen On 2021-03-24 13:16, Diego Zamboni wrote: > 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 [1] >> #+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 >> [1]") >> (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 [1]") >> (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 (陈贤文) > wrote: > > 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 > > \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="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 () > (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 > adding 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 with solutions and one without. > > What do you think? > > Yours sincerely, > Xianwen Links: ------ [1] http://printanswers.org --=_b6855e5285da850ef8fefef7e718999a Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8

Dear Diego,

Gracias!

I slightly modified your solution.

I added the #+INCLUDE line to the end of #+LATEX_HEADER, because then it= will overwrite any previous \printanswers and \noprintanswers defined in t= he HEADER.

#+TITLE:...

...

#+LATEX_HEADER: \usepackage{hyperref}
#+INCLUDE: ./latex-exam-print= answers-switch.org

I used the file name latex-exam-printanswers-switch.org, instead of prin= tanswers.org, because it gives a better indication of what it does.

I used your function as it was, except that I changed the function name = and updated the switch org file.

(defun org-latex-export-to-pdf-exam ()
  (interactive)
&n= bsp; (write-region "#+LATEX_HEADER: \\printanswers" nil "latex-exam-printan= swers-switch.org")
  (org-latex-export-to-pdf)
  (renam= e-file (org-export-output-file-name ".pdf") (org-export-output-file-name "-= with_answers.pdf"))
  (write-region "" nil "latex-exam-printanswe= rs-switch.org")
  (org-latex-export-to-pdf)
)

 

It works very fine!

Have a nice Easter!

Yours sincerely,

Xianwen



On 2021-03-24 13:16, Diego Zamboni wrote:

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 h= ave 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 "prin= tanswers.org")
  (org-latex-export-to-pdf)
  (rename-file (org-export-output-file-name ".pdf") (org-export-o= utput-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 Xi= anwen Chen (=E9=99=88=E8=B4=A4=E6=96=87) <xianwen.chen@gmail.com> wrote:

Dear Christine (and CC list),

Thank you!

 


On 2021-03-19 10:13, C= hristine Köhn wrote:

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

= I have this

\IfEndWith*{\jobname}{withsolution}{%
 &nb= sp;\usepackage{todonotes}
  \printanswers
}{\usepackage= [disable]{todonotes}}

in a myexam.sty file to switch between mod= es (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.

T= he jobname has to be passed to latex with something like -jobname
with= solution if you want it to be with solutions. I use a Makefile for
thi= s purpose which calls latexmk

latexmk -pdf -pdflatex=3D"pdflatex= --interaction=3Derrorstopmode" -use-make

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 ve= ry 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 th= e jobname from within orgmode, you'll have to change
org-latex-pdf-pro= cess 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-expor= t-define-derived-backend) and which sets
org-latex-pdf-process accordi= ngly (and resets it afterwards).
 
Thank you= again. I'm thinking of a function like following. I'm using comments to ex= press the programming detail that I don't know how to do yet.
 
(deffun o= rg-latex-export-to-pdf-exam ()
  (i= nteractive)
  # = do some emacs lisp to add \printanswers to the end of org document header, = i.e., adding a line of #+LATEX_HEADER: \printanswers
  (o= rg-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 adding a lin= e of #+LATEX_HEADER: \noprintanswers
  (o= rg-latex-export-to-pdf)
  # = remove the line of #+LATEX_HEADER: \noprintanswers
)
 
I don't k= now 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-e= xport-to-pdf-exam, it would export two PDF files, one with solutions and on= e without.
 
What do y= ou think?
 
Yours sin= cerely,
Xianwen
--=_b6855e5285da850ef8fefef7e718999a--