all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Add "latex" option to ox-bibtex.el
@ 2013-07-12  7:26 feng shu
  2013-07-12 10:36 ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: feng shu @ 2013-07-12  7:26 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org


[-- Attachment #1.1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #1.2: Type: text/html, Size: 26 bytes --]

[-- Attachment #2: 0001-Add-latex-optional-option-to-ox-bibtex.patch --]
[-- Type: application/octet-stream, Size: 3393 bytes --]

From 34d1af7f1b0ecb38000f7a19ad17f3d7bfdf26fa Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@gmail.com>
Date: Fri, 12 Jul 2013 15:14:56 +0800
Subject: [PATCH] Add "latex" optional option to ox-bibtex

* ox-bibtex.el (org-latex-keyword, org-bibtex-get-arguments):
Add `:latex' properties.

If "latex" option is set to `nil', when export to latex,
"ox-bibtex"  will not insert bibliography commands in output file.
you should insert the commands manually, for example:

\#+BIBLIOGRAPHY: foo plain option:-d latex:nil
\bibliographystyle{otherbibstyle}
\bibliography{foo}

or:

\#+BIBLIOGRAPHY: foo plain option:-d latex:nil
\printbibliography
---
 contrib/lisp/ox-bibtex.el |   21 +++++++++++++++------
 1 个文件被修改,插入 15 行(+),删除 6 行(-)

diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el
index 29a97eb..3e0b3a4 100644
--- a/contrib/lisp/ox-bibtex.el
+++ b/contrib/lisp/ox-bibtex.el
@@ -63,6 +63,12 @@
 ;;   \bibliographystyle{plain}
 ;;   \bibliography{foo}
 ;;
+;; If you prefer to use different latex command for LaTeX export,
+;; For example: \printbibliography, you can use "latex" option:
+;;
+;;   #+BIBLIOGRAPHY: foo plain option:-d latex:nil
+;;   \printbibliography
+;;
 ;; into the TeX file when exporting.
 ;;
 ;; For HTML export it:
@@ -103,21 +109,23 @@ return nil instead."
 (defun org-bibtex-get-arguments (keyword)
   "Return \"bibtex2html\" arguments specified by the user.
 KEYWORD is a \"BIBLIOGRAPHY\" keyword. Return value is a plist
-containing `:options' and `:limit' properties. The former
+containing `:options' `:limit' and `latex'  properties. The first one
 contains a list of strings to be passed as options ot
-\"bibtex2html\" process. The latter contains a boolean."
+\"bibtex2html\" process. The rest contains a boolean."
   (let ((value (org-element-property :value keyword)))
     (and value
          (string-match "\\(\\S-+\\)[ \t]+\\(\\S-+\\)\\(.*\\)" value)
-         (let (options limit)
+         (let (options limit latex)
            (dolist (arg (org-split-string (match-string 3 value))
                         ;; Return value.
-                        (list :options (nreverse options) :limit limit))
+                        (list :options (nreverse options) :limit limit :latex latex))
              (let* ((s (split-string arg ":"))
                     (key (car s))
                     (value (nth 1 s)))
                (cond ((equal "limit" key)
                       (setq limit (not (equal "nil" value))))
+		     ((equal "latex" key)
+                      (setq latex (not (equal "nil" value))))
                      ((equal "option" key) (push value options)))))))))
 
 (defun org-bibtex-citation-p (object)
@@ -148,9 +156,10 @@ Fallback to `latex' back-end for other keywords."
     (if (not (equal (org-element-property :key keyword) "BIBLIOGRAPHY"))
         ad-do-it
       (let ((file (org-bibtex-get-file keyword))
-            (style (org-bibtex-get-style keyword)))
+            (style (org-bibtex-get-style keyword))
+	    (ox-bibtex-export-latex-p (plist-get (org-bibtex-get-arguments keyword) :latex)))
         (setq ad-return-value
-              (when file
+              (when (and file ox-bibtex-export-latex-p)
                 (concat (and style (format "\\bibliographystyle{%s}\n" style))
                         (format "\\bibliography{%s}" file))))))))
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add "latex" option to ox-bibtex.el
  2013-07-12  7:26 [PATCH] Add "latex" option to ox-bibtex.el feng shu
@ 2013-07-12 10:36 ` Nicolas Goaziou
  2013-07-12 13:17   ` feng shu
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2013-07-12 10:36 UTC (permalink / raw)
  To: feng shu; +Cc: emacs-orgmode@gnu.org

Hello,

feng shu <tumashu@gmail.com> writes:

> From 34d1af7f1b0ecb38000f7a19ad17f3d7bfdf26fa Mon Sep 17 00:00:00 2001
> From: Feng Shu <tumashu@gmail.com>
> Date: Fri, 12 Jul 2013 15:14:56 +0800
> Subject: [PATCH] Add "latex" optional option to ox-bibtex
>
> * ox-bibtex.el (org-latex-keyword, org-bibtex-get-arguments):
> Add `:latex' properties.
>
> If "latex" option is set to `nil', when export to latex,
> "ox-bibtex"  will not insert bibliography commands in output file.
> you should insert the commands manually, for example:
>
> \#+BIBLIOGRAPHY: foo plain option:-d latex:nil
> \bibliographystyle{otherbibstyle}
> \bibliography{foo}
>
> or:
>
> \#+BIBLIOGRAPHY: foo plain option:-d latex:nil
> \printbibliography

Thanks for your patch.

Though, it seems a bit hackish. Can't you achive the same with hooks or
filters?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add "latex" option to ox-bibtex.el
  2013-07-12 10:36 ` Nicolas Goaziou
@ 2013-07-12 13:17   ` feng shu
  2013-07-12 13:36     ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: feng shu @ 2013-07-12 13:17 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1238 bytes --]

Really?  This problem can be resolved with hooks or filters?  Could you
give me more informations or a example?


---------- Forwarded message ----------
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Fri, Jul 12, 2013 at 6:36 PM
Subject: Re: [PATCH] Add "latex" option to ox-bibtex.el
To: feng shu <tumashu@gmail.com>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>


Hello,

feng shu <tumashu@gmail.com> writes:

> From 34d1af7f1b0ecb38000f7a19ad17f3d7bfdf26fa Mon Sep 17 00:00:00 2001
> From: Feng Shu <tumashu@gmail.com>
> Date: Fri, 12 Jul 2013 15:14:56 +0800
> Subject: [PATCH] Add "latex" optional option to ox-bibtex
>
> * ox-bibtex.el (org-latex-keyword, org-bibtex-get-arguments):
> Add `:latex' properties.
>
> If "latex" option is set to `nil', when export to latex,
> "ox-bibtex"  will not insert bibliography commands in output file.
> you should insert the commands manually, for example:
>
> \#+BIBLIOGRAPHY: foo plain option:-d latex:nil
> \bibliographystyle{otherbibstyle}
> \bibliography{foo}
>
> or:
>
> \#+BIBLIOGRAPHY: foo plain option:-d latex:nil
> \printbibliography

Thanks for your patch.

Though, it seems a bit hackish. Can't you achive the same with hooks or
filters?




Regards,

--
Nicolas Goaziou

[-- Attachment #2: Type: text/html, Size: 2213 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add "latex" option to ox-bibtex.el
  2013-07-12 13:17   ` feng shu
@ 2013-07-12 13:36     ` Nicolas Goaziou
  2013-07-12 23:15       ` feng shu
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2013-07-12 13:36 UTC (permalink / raw)
  To: feng shu; +Cc: emacs-orgmode@gnu.org

> Really?  This problem can be resolved with hooks or filters?  Could you
> give me more informations or a example?

Perhaps something like the following (untested) should do the trick:

  (defun my-bibliography-selector-hook (backend)
    (case backend
      (latex
       (when (save-excursion
               (re-search-forward "^[ \t]*\\bibliography\\(?:style\\)?{" nil t))
         (while (re-search-forward "^[ \t]*#+BIBLIOGRAPHY:.*$" nil t)
           (when (eq (org-element-type (save-match-data (org-element-at-point)))
                     'keyword)
             (replace-match "")))))
      (html
       (when (save-excursion
               (re-search-forward "^[ \t]*#+BIBLIOGRAPHY:.*$" nil t))
         (while (re-search-forward "^[ \t]*\\bibliography\\(?:style\\)?{.*$" nil t)
           (replace-match ""))))))

  (add-hook 'org-export-before-parsing-hook 'my-bibliography-selector-hook)


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add "latex" option to ox-bibtex.el
  2013-07-12 13:36     ` Nicolas Goaziou
@ 2013-07-12 23:15       ` feng shu
  2013-07-13  8:41         ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: feng shu @ 2013-07-12 23:15 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1661 bytes --]

I want to add a option which can setting bib for html export and latex
export separately,
As it for the reason:
1. bibtex2html can't work well with complex bib style, so using a simple
style and making it
    show correctly is reasonable choose,
2. bibtex2html can't find bib style in current dir, for example
(./file.sty) ,
3. the biblatex user.


In my opinion, the solution seemd more hacky than mine for a user,  It let
my org-mode file more unportable.

Could you share you opinion and reason about my approach:  Is the idea ,
separating with  a new option, hacky?  or my code hacky? .



On Fri, Jul 12, 2013 at 9:36 PM, Nicolas Goaziou <n.goaziou@gmail.com>wrote:

> > Really?  This problem can be resolved with hooks or filters?  Could you
> > give me more informations or a example?
>
> Perhaps something like the following (untested) should do the trick:
>
>   (defun my-bibliography-selector-hook (backend)
>     (case backend
>       (latex
>        (when (save-excursion
>                (re-search-forward "^[ \t]*\\bibliography\\(?:style\\)?{"
> nil t))
>          (while (re-search-forward "^[ \t]*#+BIBLIOGRAPHY:.*$" nil t)
>            (when (eq (org-element-type (save-match-data
> (org-element-at-point)))
>                      'keyword)
>              (replace-match "")))))
>       (html
>        (when (save-excursion
>                (re-search-forward "^[ \t]*#+BIBLIOGRAPHY:.*$" nil t))
>          (while (re-search-forward "^[
> \t]*\\bibliography\\(?:style\\)?{.*$" nil t)
>            (replace-match ""))))))
>
>   (add-hook 'org-export-before-parsing-hook 'my-bibliography-selector-hook)
>
>
> Regards,
>
> --
> Nicolas Goaziou
>

[-- Attachment #2: Type: text/html, Size: 3511 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add "latex" option to ox-bibtex.el
  2013-07-12 23:15       ` feng shu
@ 2013-07-13  8:41         ` Nicolas Goaziou
  2013-07-13 11:36           ` Feng Shu
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2013-07-13  8:41 UTC (permalink / raw)
  To: feng shu; +Cc: emacs-orgmode@gnu.org

Hello,

feng shu <tumashu@gmail.com> writes:

> I want to add a option which can setting bib for html export and latex
> export separately,
> As it for the reason:
> 1. bibtex2html can't work well with complex bib style, so using a simple
> style and making it
>     show correctly is reasonable choose,
> 2. bibtex2html can't find bib style in current dir, for example
> (./file.sty) ,
> 3. the biblatex user.

I understand that. Though, you didn't tell me what was wrong with the
hook I provided.

> In my opinion, the solution seemd more hacky than mine for a user,  

Of course. A hook (or a filter) is a hack. But at least, it doesn't live
in core.

> It let my org-mode file more unportable.

Portability is not an issue here. If you're really worried about it, you
need to share your configuration file along with your Org documents
anyway. If you don't, your documents will never be totally portable.

> Could you share you opinion and reason about my approach:  Is the idea ,
> separating with  a new option, hacky?  or my code hacky? .

My opinion is that we cannot add options to handle every possible use
case. That's why filters and hooks exist in the first place. Thus, when
a feature can be implemented in a couple of lines with a hook/filter,
I just ask to think twice before adding it to core.

Now, speaking about the patch, you only provide an option to ignore
"bibliography" keyword when exporting with latex back-end, but you still
have to write correct bibliography command by hand in the Org buffer.

I think a cleaner solution would be to be able to choose both
bibliography and style according to back-end from within the keyword
itself. I very much like Babel's "by-backend" approach.

That's more work for sure, but, meanwhile I think something like the
hook I provided is good enough for the job at hand.

What do you think?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Add "latex" option to ox-bibtex.el
  2013-07-13  8:41         ` Nicolas Goaziou
@ 2013-07-13 11:36           ` Feng Shu
  0 siblings, 0 replies; 7+ messages in thread
From: Feng Shu @ 2013-07-13 11:36 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Hello,
>
> feng shu <tumashu@gmail.com> writes:
>
>> I want to add a option which can setting bib for html export and latex
>> export separately,
>> As it for the reason:
>> 1. bibtex2html can't work well with complex bib style, so using a simple
>> style and making it
>>     show correctly is reasonable choose,
>> 2. bibtex2html can't find bib style in current dir, for example
>> (./file.sty) ,
>> 3. the biblatex user.
>
> I understand that. Though, you didn't tell me what was wrong with the
> hook I provided.
>
>> In my opinion, the solution seemd more hacky than mine for a user,  
>
> Of course. A hook (or a filter) is a hack. But at least, it doesn't live
> in core.
>
>> It let my org-mode file more unportable.
>
> Portability is not an issue here. If you're really worried about it, you
> need to share your configuration file along with your Org documents
> anyway. If you don't, your documents will never be totally portable.

You are right, totally protable is impossible.  My goal is that my
document can work correct in standard org-mode environment, But it seemd
impossible in real world.  emacs = toss

>
>> Could you share you opinion and reason about my approach:  Is the idea ,
>> separating with  a new option, hacky?  or my code hacky? .
>
> My opinion is that we cannot add options to handle every possible use
> case. That's why filters and hooks exist in the first place. Thus, when
> a feature can be implemented in a couple of lines with a hook/filter,
> I just ask to think twice before adding it to core.
>
> Now, speaking about the patch, you only provide an option to ignore
> "bibliography" keyword when exporting with latex back-end, but you still
> have to write correct bibliography command by hand in the Org buffer.

filter can be used in babel? for example:

#+begin_src emacs-lisp
...
#+end_src

>
> I think a cleaner solution would be to be able to choose both
> bibliography and style according to back-end from within the keyword
> itself. I very much like Babel's "by-backend" approach.
I like Babel's "by-backend" approach too, but it may be  beyond my elisp ability... :-(

Before this patch, I tested below code, failed!
I like this approach, but it may be impossible  to realize.

#+BEGIN_HTML
#+BIBLIO............
#+END_HTML


>
> That's more work for sure, but, meanwhile I think something like the
> hook I provided is good enough for the job at hand.
>
> What do you think?
>
>
> Regards,

-- 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-07-13 11:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-12  7:26 [PATCH] Add "latex" option to ox-bibtex.el feng shu
2013-07-12 10:36 ` Nicolas Goaziou
2013-07-12 13:17   ` feng shu
2013-07-12 13:36     ` Nicolas Goaziou
2013-07-12 23:15       ` feng shu
2013-07-13  8:41         ` Nicolas Goaziou
2013-07-13 11:36           ` Feng Shu

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.