* Re: export to latex without labels [not found] <mailman.83.1405785624.1721.emacs-orgmode@gnu.org> @ 2014-07-19 20:24 ` Salome Soedergran 2014-07-20 3:18 ` Eric Abrahamsen 0 siblings, 1 reply; 6+ messages in thread From: Salome Soedergran @ 2014-07-19 20:24 UTC (permalink / raw) To: emacs-orgmode Hi Eric, Eric Abrahamsen <eric@ericabrahamsen.net> writes: > 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? > [...] > Hmm, that might have been too much information. What I'm proposing is > just this: > > (defun ks/org-latex-remove-labels (string backend info) > "Remove labels generated by org-mode" > (if (org-export-derived-backend-p backend 'latex) > "" > string)) > > (eval-after-load 'ox-latex > '(add-to-list 'org-export-filter-target-functions > 'ks/org-latex-remove-labels)) > Thank you so much for your explanations! That was NOT too much information but exactly what I'd been hoping for. It's this sort of information that helps me to come to a better understanding of emacs. I have tested your suggestion with just no result whatsoever. But with the help of your explanations I've managed to change my bit of code accordingly and now it works: (defun ks/org-latex-remove-labels (string 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-in-string "\\\\label{sec-[0-9][^}]*}\n" "" string) ))) (eval-after-load 'ox-latex '(add-to-list 'org-export-filter-final-output-functions 'ks/org-latex-remove-labels)) Thanks again! Salome ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: export to latex without labels 2014-07-19 20:24 ` export to latex without labels Salome Soedergran @ 2014-07-20 3:18 ` Eric Abrahamsen 0 siblings, 0 replies; 6+ messages in thread From: Eric Abrahamsen @ 2014-07-20 3:18 UTC (permalink / raw) To: emacs-orgmode "Salome Soedergran" <salome.soedergran@gmx.ch> writes: > Hi Eric, > > Eric Abrahamsen <eric@ericabrahamsen.net> writes: >> 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? >> > [...] >> Hmm, that might have been too much information. What I'm proposing is >> just this: >> >> (defun ks/org-latex-remove-labels (string backend info) >> "Remove labels generated by org-mode" >> (if (org-export-derived-backend-p backend 'latex) >> "" >> string)) >> >> (eval-after-load 'ox-latex >> '(add-to-list 'org-export-filter-target-functions >> 'ks/org-latex-remove-labels)) >> > > Thank you so much for your explanations! That was NOT too much information but exactly what I'd been hoping for. It's this sort of information that helps me to come to a better understanding of emacs. > I have tested your suggestion with just no result whatsoever. But with > the help of your explanations I've managed to change my bit of code > accordingly and now it works: Yes, that's the danger with totally untested suggestions :) Turns out the \labels are hard-coded, and the "target" stuff is something else entirely. Glad you got it working, despite that! > (defun ks/org-latex-remove-labels (string 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-in-string "\\\\label{sec-[0-9][^}]*}\n" "" string) > ))) > (eval-after-load 'ox-latex > '(add-to-list 'org-export-filter-final-output-functions > 'ks/org-latex-remove-labels)) > > Thanks again! Salome ^ permalink raw reply [flat|nested] 6+ messages in thread
* export to latex without labels @ 2014-07-19 14:02 Salome =?iso-8859-1?Q?S=F6dergran ?= 2014-07-19 14:40 ` Eric Abrahamsen 0 siblings, 1 reply; 6+ messages in thread From: Salome =?iso-8859-1?Q?S=F6dergran ?= @ 2014-07-19 14:02 UTC (permalink / raw) To: emacs-orgmode 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 [1] http://stackoverflow.com/questions/18076328/org-mode-export-to-latex-suppress-generation-of-labels ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: export to latex without labels 2014-07-19 14:02 Salome =?iso-8859-1?Q?S=F6dergran ?= @ 2014-07-19 14:40 ` Eric Abrahamsen 2014-07-19 14:47 ` Eric Abrahamsen 2014-07-19 16:05 ` Nick Dokos 0 siblings, 2 replies; 6+ messages in thread From: Eric Abrahamsen @ 2014-07-19 14:40 UTC (permalink / raw) To: emacs-orgmode "Salome "Södergran\"" <salome.soedergran@gmx.ch> 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: export to latex without labels 2014-07-19 14:40 ` Eric Abrahamsen @ 2014-07-19 14:47 ` Eric Abrahamsen 2014-07-19 16:05 ` Nick Dokos 1 sibling, 0 replies; 6+ messages in thread From: Eric Abrahamsen @ 2014-07-19 14:47 UTC (permalink / raw) To: emacs-orgmode Eric Abrahamsen <eric@ericabrahamsen.net> writes: > "Salome "Södergran\"" <salome.soedergran@gmx.ch> 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? Hmm, that might have been too much information. What I'm proposing is just this: (defun ks/org-latex-remove-labels (string backend info) "Remove labels generated by org-mode" (if (org-export-derived-backend-p backend 'latex) "" string)) (eval-after-load 'ox-latex '(add-to-list 'org-export-filter-target-functions 'ks/org-latex-remove-labels)) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: export to latex without labels 2014-07-19 14:40 ` Eric Abrahamsen 2014-07-19 14:47 ` Eric Abrahamsen @ 2014-07-19 16:05 ` Nick Dokos 1 sibling, 0 replies; 6+ messages in thread From: Nick Dokos @ 2014-07-19 16:05 UTC (permalink / raw) To: emacs-orgmode Eric Abrahamsen <eric@ericabrahamsen.net> writes: > "Salome "Södergran\"" <salome.soedergran@gmx.ch> 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. >> ... > > ... > Really really lastly, does it really matter if there are unused \labels > in the output? > What he said: stop worrying and (let org export) label everything :-) In a similar vein, in N. David Mermin's *wonderful* book "Boojums all the way through", there is a chapter entitled "What's wrong with these equations?" (the article is available on line at http://www.ai.mit.edu/courses/6.899/papers/mermin.pdf - but the whole book is worth reading) where he mentions Fisher's rule: number *every* equation in your manuscript. -- Nick ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-07-20 3:15 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <mailman.83.1405785624.1721.emacs-orgmode@gnu.org> 2014-07-19 20:24 ` export to latex without labels Salome Soedergran 2014-07-20 3:18 ` Eric Abrahamsen 2014-07-19 14:02 Salome =?iso-8859-1?Q?S=F6dergran ?= 2014-07-19 14:40 ` Eric Abrahamsen 2014-07-19 14:47 ` Eric Abrahamsen 2014-07-19 16:05 ` Nick Dokos
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.