From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: export to latex without labels Date: Sat, 19 Jul 2014 22:40:49 +0800 Message-ID: <87y4vpmmxa.fsf@ericabrahamsen.net> References: <21450.31333.840496.200548@gargle.gargle.HOWL> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8Vp3-0008Vt-8s for emacs-orgmode@gnu.org; Sat, 19 Jul 2014 10:41:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X8Vox-0007RJ-7I for emacs-orgmode@gnu.org; Sat, 19 Jul 2014 10:41:13 -0400 Received: from plane.gmane.org ([80.91.229.3]:59472) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8Vow-0007RC-W7 for emacs-orgmode@gnu.org; Sat, 19 Jul 2014 10:41:07 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1X8Vow-0003wp-7K for emacs-orgmode@gnu.org; Sat, 19 Jul 2014 16:41:06 +0200 Received: from 111.197.167.73 ([111.197.167.73]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 19 Jul 2014 16:41:06 +0200 Received: from eric by 111.197.167.73 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 19 Jul 2014 16:41:06 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org "Salome "Södergran\"" writes: > Hello experts, > > I've been fiddling around for a while now with the following problem: > > When I export something from org to latex I get plenty of \labels that I never refer to. I'd like to get rid of all those labels. > I found some code [1] that uses a hook that does not work in orgmode anymore. So I tried to adapt that code to the new orgmode way with org-export-filter-final-functions: > > (defun ks/org-latex-remove-labels (backend info) > "Remove labels generated by org-mode" > (when (org-export-derived-backend-p backend 'latex) > (let ((case-fold-search nil)) > (goto-char 1) > (replace-regexp "\\\\label{sec-[0-9][^}]*}" "") > ))) > > (eval-after-load 'ox-latex > '(add-to-list 'org-export-filter-final-output-functions > 'ks/org-latex-remove-labels)) > > > When I now try to export something from org to latex, I get the following error message: > Wrong number of arguments: (lambda (backend) "Remove labels generated by org-mode" (if (org-export-derived-backend-p backend (quote latex)) (progn (let ((case-fold-search nil)) (goto-char 1) (replace-regexp "\\\\label{sec-[0-9][^}]*}" ""))))), 3 > > I am just an emacs user, not a programmer, and I have no idea what's wrong and what I have to change to make it work. Can anyone give me a hint? > TIA, Salome The error message is telling you that the wrong number of arguments were passed to your filter function. If you look at the doctoring of org-export-filter-final-output-functions, you'll see that functions in this filter are passed three arguments (note the 3 at the end of your error message), but your function only accepts two. Once you've sorted that out, you'll see that the argument you're missing is an argument representing the full exported string. That means that `replace-regexp' is probably the wrong function to be using inside your function. Actually, if you look at the docstring of replace-regexp, that was the wrong function to be using anyway :) It recommends using a combination of re-search-forward and replace-match in lisp functions. Since you've got a string, try replace-regexp-in-string instead! See the docstring... Lastly, it's possible that you could use a more narrowly-targeted filter for this particular case (rather than filter-final-output, which doesn't kick in until everything else is done). When exporting to latex, the element that turns into \label is a target, and that happens in org-latex-target. The corresponding filter is org-export-filter-target-functions, so you might consider putting your function in that variable instead. That could be much simpler: the function would take three arguments, the second of which is the backend, as a symbol. You could just check if the symbol was 'latex, and have the function return an empty string. The function body could be as simple as: (defun org-latex-remove-labels (string backend data) (if (org-export-derived-backend-p backend 'latex) "" string)) I haven't tested this for unexpected consequences, mind you... Really really lastly, does it really matter if there are unused \labels in the output? E