Re: LaTeX fragments not being generated due to extra * in tikz env

2020-12-17 Thread Thibault Marin

Hi,

I introduced the change that broke the behavior.  The attached patch
seems to fix the issue for me, does it look reasonable?

Thanks,

thibault

On 2020-12-09T13:16:19-0500, Jeremie Juste wrote:

  Hello,

  Thanks for reporting. Indeed this is an issue that hasn't been fixed
  yet. This is the case for most latex environments

  My solution is here
  https://www.mail-archive.com/emacs-orgmode@gnu.org/msg129974.html

  but consider also the idea behind the star
  https://www.mail-archive.com/emacs-orgmode@gnu.org/msg129976.html

  I will try to submit a patch soon.

  Best regards,
  Jeremie

  On Tuesday,  8 Dec 2020 at 20:57, 10cadr wrote:
  > I was trying out the new option tex:dvipng. The HTML result was a image
  > with the tikz code.
  >
  > Turns out, debugging and telling the fragment processor not to delete the
  > files, what org generates for the tikz fragment is:
  >
  > \begin{tikzpicture*}
  >
  > Removing the astherisk would make it work without any workarounds.
  >
  > How I got around this was
  >
  > #+LATEX_HEADER: \usepackage{environ,amsmath,multicol}
  > #+LATEX_HEADER:
  > 
\NewEnviron{tikzpicture*}[1][]{\begin{tikzpicture}[#1]\BODY\end{tikzpicture}}
  >
  > Possibly fixing this issue, will make cross formats much easier.

  --
  Jeremie Juste


From f5122a85b0170f17be103400b5f910030df806c4 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Thu, 10 Dec 2020 13:26:08 -0500
Subject: [PATCH] Fix non-math environment export

* ox-html.el (org-html-latex-environment): Prevent addition of * to
non-math environments.  Added * is used for math environments to
replace latex equation numbering by org labels for html linking.
---
 lisp/ox-html.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index d2f24f5c6..40024c70b 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2933,7 +2933,9 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
  ((assq processing-type org-preview-latex-process-alist)
   (let ((formula-link
  (org-html-format-latex
-  (org-html--unlabel-latex-environment latex-frag)
+	  (if (eq nil (org-html--math-environment-p latex-environment))
+		  latex-frag
+		(org-html--unlabel-latex-environment latex-frag))
   processing-type info)))
 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
   (let ((source (org-export-file-uri (match-string 1 formula-link
--
2.29.2



Re: latex fragments compilation error when exporting to html

2020-09-02 Thread Thibault Marin
Hi,

I can't comment on the rest of the discussion but I think I added this
org-html--unlabel-latex-environment line.  It was part of a change
allowing links to equations in HTML export
(https://lists.gnu.org/archive/html/emacs-orgmode/2018-01/msg00120.html).

When removing the call to org-html--unlabel-latex-environment, exporting
the following org file to html results in double equation labels (one
from dvipng, one from org to allow links).

,
| #+OPTIONS: toc:nil html-postamble:nil tex:dvipng
|
| #+NAME: eq-test
| \begin{align}
| 1 + 1 = 0
| \end{align}
|
| link to equation [[eq-test]]
`
(one could play with tex:mathjax and replace align by align* to see the
possible modes)

If I understand the problem correctly, one solution would be to apply
the environment transformation from env to env* only for math
environments.  Something along the lines of
,
| (if (eq nil (org-html--math-environment-p latex-environment))
| latex-frag
|   (org-html--unlabel-latex-environment latex-frag))
`
may work (there may be a better way to do that).

I hope this helps.

Best,

thibault

On 2020-09-02T02:12:01-0400, Jeremie Juste wrote:


  Hello,

  I have found the culprit in the end. It was the function
  org-html--unlabel-latex-environment, int he ox-html.el file.

  I'm not sure this function is useful as I think it is better to give the
  user control on his environment (labelled or unlabelled) directly in his
  org file. I'm I missing something else about the use of this function?

  Anyway it was a good experience at debugging elisp.


  diff --git a/lisp/ox-html.el b/lisp/ox-html.el
  index 55d017529..b2a5d6d36 100644
  --- a/lisp/ox-html.el
  +++ b/lisp/ox-html.el
  @@ -2891,7 +2891,7 @@ CONTENTS is nil.  INFO is a plist holding contextual 
information."
((assq processing-type org-preview-latex-process-alist)
 (let ((formula-link
(org-html-format-latex
  -  (org-html--unlabel-latex-environment latex-frag)
  +  latex-frag
 processing-type info)))
   (when (and formula-link (string-match "file:\\([^]]*\\)" 
formula-link))
 (let ((source (org-export-file-uri (match-string 1 formula-link


  Best regards,
  Jeremie

  - GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.5, cairo 
version 1.16.0) of 2020-09-01
  - Org mode version 9.3.7 (release_9.3.7-725-g7bc18e @ 
/home/djj/src/org-mode/lisp/)



Re: Bug: org-mime-htmlize generates unwanted equations numbers in mail [9.2.5 (release_9.2.5-521-gdea0c7 @ /home/oub/emacs/site-lisp/packages/org/)]

2019-12-08 Thread Thibault Marin

Hi, thanks for the quick review.

On 2019-12-08T15:40:54-0500, Nicolas Goaziou wrote:


> > +(defun org-html--latex-environment-numbered-p (latex-frag)
>   ^^
>   latex-env

I changed the name and docstring to `element' (similar to
`org-html--math-environment-p'.

> > +  "Return t if LATEX-ENV contains a numbered environment.

> Non-nil if...

Done.

> However, I suggest to make this function operate on the element itself,
> not its value, much like `org-html--math-environment-p'.

Done (if I understood correctly).

> I suggest merging the two regexps into a single one, and use:

> (not (string-match-p REGEXP latex-env))

Done

> Operating directly on the element will be a bit nicer. Why do you need
> `org-remove-indentation'?

I looks like I didn't.  I removed it.

> Could you send an updated patch and provide an ORG-NEWS entry (on top of
> master)?

See attached.

Thanks,

thibault

From 3cf6b644f2b7d806b15dd5e76914b1547ef77a96 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Sat, 2 Nov 2019 02:12:38 -0400
Subject: [PATCH] ox-html: Add equation numbers only for numbered environments

* lisp/ox-html.el (org-html-latex-environment): Add caption to numbered
environments only
(org-html--latex-environment-numbered-p): Determine whether a latex
environment should be numbered.
---
 etc/ORG-NEWS|  8 
 lisp/ox-html.el | 32 ++--
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index e61b97fa5..f20e4ea98 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -21,6 +21,14 @@ just as if it was at outline level 0.  Inheritance for properties will
 work also for this level.  In other words: defining things in a
 property drawer before the first headline will make them "inheritable"
 for all headlines.
+
+*** Restrict the addition of a label to LaTeX equations in HTML export to numbered environments only
+
+Prevent the addition of a label to LaTeX math environments in HTML
+export when not in a numbered environment (numbered environment are
+everything but =displaymath= and environments ending with a star
+character, e.g. =equation*=).
+
 ** New functions
 *** ~org-columns-toggle-or-columns-quit~
 == bound to ~org-columns-toggle-or-columns-quit~ replaces the
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 83d0fd2e9..2f2210aa1 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2914,19 +2914,31 @@ For instance, change an 'equation' environment to 'equation*'."
 			 latex-frag nil nil 1)
nil nil 1))

+(defun org-html--latex-environment-numbered-p (element)
+  "Non-nil if ELEMENT contains a numbered LaTeX math environment.
+
+Environments with a star (*) character and displaymath are not numbered."
+  (not (string-match-p
+	"\\`[ \t]*begin{\\(.*\\*\\|displaymath\\)}"
+	(org-element-property :value element
+
 (defun org-html-latex-environment (latex-environment _contents info)
   "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  (let ((processing-type (plist-get info :with-latex))
-	(latex-frag (org-remove-indentation
-		 (org-element-property :value latex-environment)))
-(attributes (org-export-read-attribute :attr_html latex-environment))
-(label (and (org-element-property :name latex-environment)
-(org-export-get-reference latex-environment info)))
-(caption (number-to-string
-  (org-export-get-ordinal
-   latex-environment info nil
-   #'org-html--math-environment-p
+  (let* ((processing-type (plist-get info :with-latex))
+	 (latex-frag (org-remove-indentation
+		  (org-element-property :value latex-environment)))
+ (attributes (org-export-read-attribute :attr_html latex-environment))
+ (label (and (org-element-property :name latex-environment)
+ (org-export-get-reference latex-environment info)))
+	 (caption (when (org-html--latex-environment-numbered-p
+			 latex-environment)
+		(number-to-string
+		 (org-export-get-ordinal
+		  latex-environment info nil
+		  (lambda (l info)
+			(and (org-html--math-environment-p l)
+			 (org-html--latex-environment-numbered-p l
 (cond
  ((memq processing-type '(t mathjax))
   (org-html-format-latex
--
2.24.0



Re: Bug: org-mime-htmlize generates unwanted equations numbers in mail [9.2.5 (release_9.2.5-521-gdea0c7 @ /home/oub/emacs/site-lisp/packages/org/)]

2019-12-08 Thread Thibault Marin

Dear maintainers,

Following-up on this bug report regarding the handling of unnumbered
equation environments in HTML export, I would like to propose the
attached patch.  The patch simply removes the caption for unnumbered
environments.

Could you please let me know whether this could be considered for a
merge and if there any comments or suggestions to improve it?

Thanks in advance.

thibault


On 2019-11-02T05:38:04-0400, Uwe Brauer wrote:

  >>> "TM" == Thibault Marin  writes:

 > Hi,

 > I think I wrote some of that code, I was not trying to support
 > "unnumbered" environments.  If I understand correctly, this is what you
 > are trying to get.

 > The attached patch attempts to solve this.  Currently, `displaymath' and
 > `*' environments do not get numbers, I am not sure if there are other
 > environments that should not get numbers; please let me know if you have
 > others in mind.


  Thanks very much, I pulled the latest master, applied your patch,
  compiled and installed, and everything works *now* as expected.

  The only environments without numbers which I use regularly are.
   align* and sometimes eqnarray*


  but these are all covered
 > If you (and others) could test and/or review the patch, we could
 > probably get it merged at some point.

  That would be great, thanks again

  @Eric, I wonder why you did not get these numbers without the patch!

  Uwe

From 41a7fc5c1580a45610b63b0c357f0e07884ce27b Mon Sep 17 00:00:00 2001
From: thibault 
Date: Sat, 2 Nov 2019 02:12:38 -0400
Subject: [PATCH] ox-html: Add equation numbers only for numbered environments

* lisp/ox-html.el (org-html-latex-environment): Add caption to numbered
environments only
(org-html--latex-environment-numbered-p): Determine whether a latex
environment should be numbered.
---
 lisp/ox-html.el | 36 ++--
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 83d0fd2e9..55983ff2f 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2914,19 +2914,35 @@ For instance, change an 'equation' environment to 'equation*'."
 			 latex-frag nil nil 1)
nil nil 1))

+(defun org-html--latex-environment-numbered-p (latex-frag)
+  "Return t if LATEX-ENV contains a numbered environment.
+
+Environments with a star (*) character and displaymath are not numbered."
+  (not (some 'identity
+	 (mapcar (lambda (el)
+		   (string-match el latex-frag))
+		 '("\\`[ \t]*begin{[^*}]+?[*]}"
+		   "\\`[ \t]*begin{displaymath}")
+
 (defun org-html-latex-environment (latex-environment _contents info)
   "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  (let ((processing-type (plist-get info :with-latex))
-	(latex-frag (org-remove-indentation
-		 (org-element-property :value latex-environment)))
-(attributes (org-export-read-attribute :attr_html latex-environment))
-(label (and (org-element-property :name latex-environment)
-(org-export-get-reference latex-environment info)))
-(caption (number-to-string
-  (org-export-get-ordinal
-   latex-environment info nil
-   #'org-html--math-environment-p
+  (let* ((processing-type (plist-get info :with-latex))
+	 (latex-frag (org-remove-indentation
+		  (org-element-property :value latex-environment)))
+ (attributes (org-export-read-attribute :attr_html latex-environment))
+ (label (and (org-element-property :name latex-environment)
+ (org-export-get-reference latex-environment info)))
+	 (caption (when (org-html--latex-environment-numbered-p
+			 latex-frag)
+		(number-to-string
+		 (org-export-get-ordinal
+		  latex-environment info nil
+		  (lambda (l info)
+			(and (org-html--math-environment-p l)
+			 (org-html--latex-environment-numbered-p
+			  (org-remove-indentation
+			   (org-element-property :value l))
 (cond
  ((memq processing-type '(t mathjax))
   (org-html-format-latex
--
2.24.0



Re: org-custom-id-goto?

2019-12-04 Thread Thibault Marin



> I'd also be happy with a helm interface to the actual headline text

I use `helm-semantic-or-imenu' to navigate between org headlines, it may
partly fit your needs.





Re: Bug: org-mime-htmlize generates unwanted equations numbers in mail [9.2.5 (release_9.2.5-521-gdea0c7 @ /home/oub/emacs/site-lisp/packages/org/)]

2019-11-02 Thread Thibault Marin

Hi,

I think I wrote some of that code, I was not trying to support
"unnumbered" environments.  If I understand correctly, this is what you
are trying to get.

The attached patch attempts to solve this.  Currently, `displaymath' and
`*' environments do not get numbers, I am not sure if there are other
environments that should not get numbers; please let me know if you have
others in mind.

If you (and others) could test and/or review the patch, we could
probably get it merged at some point.

Thanks,

thibault

On 2019-11-01T09:55:49-0400, Uwe Brauer wrote:

  >>> "FE" == Fraga, Eric  writes:

 > On Friday,  1 Nov 2019 at 08:52, Uwe Brauer wrote:
 >> As the attached screenshots show, the png contain unwanted equations
 >> numbers (displaymath adn equation* have been used which should not
 >> generate those numbers).

 > Uwe,

 > when I invoke org-mime-htmlize with your equations, as written, I do not 
get any equation numbers.

  Thanks, so it is my setting. I wounder how can I debug this?

From d66392545762f0ed890a772e08dad3655ea7e522 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Sat, 2 Nov 2019 02:12:38 -0400
Subject: [PATCH] ox-html: Add equation numbers only for numbered environments

* lisp/ox-html.el (org-html-latex-environment): Add caption to numbered
environments only
(org-html--latex-environment-numbered-p): Determine whether a latex
environment should be numbered.
---
 lisp/ox-html.el | 36 ++--
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 83d0fd2e9..55983ff2f 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2914,19 +2914,35 @@ For instance, change an 'equation' environment to 'equation*'."
 			 latex-frag nil nil 1)
nil nil 1))

+(defun org-html--latex-environment-numbered-p (latex-frag)
+  "Return t if LATEX-ENV contains a numbered environment.
+
+Environments with a star (*) character and displaymath are not numbered."
+  (not (some 'identity
+	 (mapcar (lambda (el)
+		   (string-match el latex-frag))
+		 '("\\`[ \t]*begin{[^*}]+?[*]}"
+		   "\\`[ \t]*begin{displaymath}")
+
 (defun org-html-latex-environment (latex-environment _contents info)
   "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  (let ((processing-type (plist-get info :with-latex))
-	(latex-frag (org-remove-indentation
-		 (org-element-property :value latex-environment)))
-(attributes (org-export-read-attribute :attr_html latex-environment))
-(label (and (org-element-property :name latex-environment)
-(org-export-get-reference latex-environment info)))
-(caption (number-to-string
-  (org-export-get-ordinal
-   latex-environment info nil
-   #'org-html--math-environment-p
+  (let* ((processing-type (plist-get info :with-latex))
+	 (latex-frag (org-remove-indentation
+		  (org-element-property :value latex-environment)))
+ (attributes (org-export-read-attribute :attr_html latex-environment))
+ (label (and (org-element-property :name latex-environment)
+ (org-export-get-reference latex-environment info)))
+	 (caption (when (org-html--latex-environment-numbered-p
+			 latex-frag)
+		(number-to-string
+		 (org-export-get-ordinal
+		  latex-environment info nil
+		  (lambda (l info)
+			(and (org-html--math-environment-p l)
+			 (org-html--latex-environment-numbered-p
+			  (org-remove-indentation
+			   (org-element-property :value l))
 (cond
  ((memq processing-type '(t mathjax))
   (org-html-format-latex
--
2.23.0



Re: [O] blogging wih org-mode

2019-09-29 Thread Thibault Marin


Last time I researched this, this was the list I obtained:

http://bastibe.de/2013-11-13-blogging-with-emacs.html

http://endlessparentheses.com/how-i-blog-one-year-of-posts-in-a-single-org-file.html
https://github.com/howardabrams/dot-files/blob/master/emacs-blog.org
http://www.john2x.com/blog/blogging-with-orgmode.html
https://ogbe.net/blog/blogging_with_org.html
http://nicolas.petton.fr/blog/blogging-with-org-mode.html

This may be a little out-dated, I think ox-hugo is pretty popular
nowadays.

I built one a while ago
(https://thibaultmarin.github.io/blog/posts/2016-11-13-Personal_website_in_org.html)
using org-mode only, but I wouldn't call it simple.  There may still
be some useful things in there.

Hope it helps.

On 2019-09-29T18:06:27-0400, Joseph Vidal-Rosset wrote:

  Hi the list,

  I would be glad to know what is, according to the majority, the best
  tool to blog with org-mode. I'm searching something simple to use and
  to install in order to blog with emacs, and, ideally, with emacs and
  org-mode only.

  (I met  difficulties with lazyblorg, for example. I did not succeed to
  understand how it works.)

  Thanks for your help.

  Jo.



Re: [O] getting access to a self-invented option?

2019-08-02 Thread Thibault Marin
Hi,

I am not sure where you are trying to get to the value (in the
publishing function?), but I use something like the following to handle
custom keywords:

,
| #+MWP_EXPORT_TYPE: slides
|
| #+name: elt
| #+begin_src emacs-lisp :results silent :exports none
| (let ((tree (org-element-parse-buffer)))
|   (org-element-map
|   tree 'keyword
| (lambda (r)
|   (let ((key (org-element-property :key r))
| (value (org-element-property :value r)))
| (when (string= key "MWP_EXPORT_TYPE")
|   value))) ;; Return the keyword value
| nil t))
| #+end_src
`

If you have access to the parsed tree or the buffer filename, you may be
able to use this or something similar (maybe wrapped in a function).

Hope it helps.

On 2019-08-02T12:10:18-0400, Matt Price wrote:

  I'm trying to streamline some veyr ad-hoc workflows I have. One thing I do
  a lot during the school year is make some changes to an org source file,
  and then export to hugo markdown with ox-hugo, and finally commit to git
  (after that I have a git hook that generates the website & uploads the
  changed pages to the appropriate location, usually a github-pages branch or
  separate repo).

  So I have this code:

  (defun mwp-hugo-export-and-release ()
"Make it faster and easier to put my lectures up on the website."
(interactive)

(let* ((modfile (org-hugo-export-wim-to-md))
   (basedir (plist-get  (org-export-get-environment 'hugo)
  ':hugo-base-dir ))
   (default-directory (expand-file-name basedir)))
  (magit-stage-file modfile)
  ;; (magit-status)
  (magit-commit-create)
  )  )

  It works great, I'm very happy. HOWEVER: in my websites I have two kinds of
  outputs:

  - regular pages -- these get exported to .md files and turned into html by
  hugo
  - lecture notes -- these get exported to reveal.js HTML pages by
  org-re-reveal and my hugo theme treats them differently .

  I would really like to set a switch somewhere in the file, something like:

  #+MWP_EXPORT_TYPE: slides

  And then something like

  let* ((modfile (if (eq :mwp-export-type "slides")
  (mwp-hugo-reveal-custom-export-function)
 (org-hugo-export-wim-to-md)))
   etc)
  do stuff)


  But I'm not sure how to get access to a totally non-standard option like
  the kind I just invented in that last bit of pseudo-code. Anyone have a
  good suggestion?

  Thank you as always!

  Matt




Re: [O] Org publish inserting HTML tags into sitemap-format-entry

2019-07-10 Thread Thibault Marin


Right, sorry I thought that would be easier.

The closest I can get is with a global macro (called `div' in the following):

,
| (defun org-sitemap-custom-entry-format (entry style project)
|   "Custom sitemap entry formatting: add date"
|   (cond ((not (directory-name-p entry))
|  (format "[[file:%s][(%s) %s]]{{{div(%s)}}}\n"
|  entry
|  (format-time-string "%Y-%m-%d"
|  (org-publish-find-date entry project))
|  (org-publish-find-title entry project)
|  (format-time-string "%Y-%m-%d"
|  (org-publish-find-date entry project
| ((eq style 'tree)
|  ;; Return only last subdir.
|  (file-name-nondirectory (directory-file-name entry)))
| (t entry)))
`

The macro is global:
,
| (setq org-export-global-macros
|   '(("div" . "@@html:$1@@")))
`

The only(?) problem is that I get a line return between the title and
the date in the sitemap.  I wonder if this can be fixed, maybe by
passing extra options to `org-list-to-generic'.

This may be a starting point.


On 2019-07-10T20:30:42-0400, Thomas Ingram wrote:

  Thanks, but adding `#+begin_export html' simply outputs that as well
  without changing the output

  "#+begin_export html
  %s [[file:blog/%s][%s]]
  #+end_export"

  Produces

  #+beginexporthtml div
  class="timestamp"2019-07-10/div Test#+endexport

  On 7/10/19 7:47 PM, Thibault Marin wrote:
  > You may need to wrap the html part in a `#+begin_export html' block or
  > similar.  I believe the custom sitemap function should generate org
  > content, not directly HTML.
  >
  > Hope it helps.
  >
  > On 2019-07-10T17:44:01-0400, Thomas Ingram wrote:
  >
  >Hello,
  >
  >I am using ox-publish to build my website. I have a custom
  >sitemap-formt-entry function that adds post dates and I'm trying to
  >add a div around those dates. Problem is the tags are getting escaped
  >in the resulting HTML. How can I add tags without them being escaped?
  >
  >Below is my :sitemap-format-entry function.
  >
  >(defun org-sitemap-custom-entry-format (entry style project)
  > (let ((filename (org-publish-find-title entry project)))
  > (if (= (length filename) 0)
  > (format "*%s*" entry)
  > (format "%s [[file:blog/%s][%s]]"
  > (format-time-string "%Y-%m-%d"
  > (org-publish-find-date entry project))
  > entry
  > filename
  >
  >Thanks for the help!
  >
  >Thomas Ingram
  >
  >
  >





Re: [O] Org publish inserting HTML tags into sitemap-format-entry

2019-07-10 Thread Thibault Marin


You may need to wrap the html part in a `#+begin_export html' block or
similar.  I believe the custom sitemap function should generate org
content, not directly HTML.

Hope it helps.

On 2019-07-10T17:44:01-0400, Thomas Ingram wrote:

  Hello,

  I am using ox-publish to build my website. I have a custom
  sitemap-formt-entry function that adds post dates and I'm trying to
  add a div around those dates. Problem is the tags are getting escaped
  in the resulting HTML. How can I add tags without them being escaped?

  Below is my :sitemap-format-entry function.

  (defun org-sitemap-custom-entry-format (entry style project)
   (let ((filename (org-publish-find-title entry project)))
   (if (= (length filename) 0)
   (format "*%s*" entry)
   (format "%s [[file:blog/%s][%s]]"
   (format-time-string "%Y-%m-%d"
   (org-publish-find-date entry project))
   entry
   filename

  Thanks for the help!

  Thomas Ingram






Re: [O] org-mode blogging

2018-12-22 Thread Thibault Marin


I have done something similar with the sitemap functionality:
- I used the sitemap functions to extract date and title from the page:
  
https://thibaultmarin.github.io/blog/posts/2016-11-13-Personal_website_in_org.html#sitemap
- The sitemap is added in the main page to show a list of blog posts:
  
https://thibaultmarin.github.io/blog/posts/2016-11-13-Personal_website_in_org.html#index_org
- For the RSS feed, I wrote a simple function to extract the first
  paragraph of the blog post (there is probably a better way to do this).

I don't know of a standard way to do this, but this seems to work and
approach your needs.

Hope it helps.

thibault

On 2018-12-22T11:57:01-0500, Roy Lemmon wrote:

  I have setup a blog using org mode publish.

  I can easily list all blog posts on a page. However I would like to list
  the blog title, first few lines and date. Then be able to provide a link to
  another page with the full blog post.

  Is there a standard way to do this or do I need to use some elisp to
  extract the title and first few lines manually ?

  Thanks for any hints.

  Roy.




Re: [O] Problem with python source block

2018-05-25 Thread Thibault Marin

Hi,

For what it's worth, I cannot reproduce it on Org mode version 9.1.13
(release_9.1.13-763-g2621db) with -Q; the file is properly produced.

I get the same error if I add the `session' header argument, maybe it is
set elsewhere?

Hope it helps.

thibault

Doyley, Marvin M. writes:

> Hi there,
>
> When I run the following code I get an error, does anybody know how to fix 
> this
>
> I am using the latest version of org-mode.
>
> Thanks,
> M
>
>
> #+BEGIN_SRC python :results file
> import numpy as np
> import matplotlib.pyplot as plt
> import seaborn as sns
> x = np.random.rand(100)
> y= np.cos(x)
> plt.plot(x,y)
> plt.savefig('test.png')
> return 'test.png'
> #+END_SRC
>
> #+RESULTS:
> [[file:  File "Org SRC", line 8
> return 'test.png'
> ^
> SyntaxError: 'return' outside function
> ]]



Re: [O] ox-md: Export links to equations for use with MathJax

2018-02-12 Thread Thibault Marin

> Markdown has no direct business with Mathjax, so introducing Mathjax
> components in "ox-md.el" sounds wrong to me. "ox-md.el" doesn't even
> have any math-related function (it lets "ox-html.el" take care of LaTeX
> fragments and environments).
OK.

> Since it is a specific requirement, you may want to define your own
> Markdown back-end in this case (e.g., replacing `org-md-link' with
> `org-html-link' in some cases).

Thanks.  The following seems to work for my need:

,
| (defun org-ipynb-link (link desc info)
|   (let* ((type (org-element-property :type link))
|(destination (if (string= type "fuzzy")
| (org-export-resolve-fuzzy-link link info
|   (if (and destination
|(eq 'latex-environment (org-element-type destination))
|(eq 'math (org-latex--environment-type destination)))
|   (org-html-link link desc info)
| (org-md-link link desc info
`

Thanks for the help.

thibault



[O] ox-md: Export links to equations for use with MathJax

2018-02-10 Thread Thibault Marin

Hi list,

Similar to a change introduced recently to ox-html (ba6c0f1ea9), I'd
like to be able to export (in markdown, using ox-md.el) links to LaTeX
equations with "\eqref{org000}" and rely on MathJax for rendering
instead of the default markdown format ("[description][#org000]").

The attached patch is my first attempt at this.  It is almost identical
to the ox-html version.  I have added an option to select which mode to
use (markdown or MathJax).

Could this patch be considered for a merge?  Please let know if there
are any suggestions or comments.

Thanks,

thibault

>From bf03749fe18726f43684d0818a75a2affbe3e546 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Sat, 10 Feb 2018 22:58:35 -0600
Subject: [PATCH] ox-md.el: Add option to export equation links to "\eqref"
 (MathJax)

* lisp/ox-md.el (org-md-link): Export link to LateX equation as
"\eqref" (for use with MathJax) when the new option `:md-link-mathjax'
is non-nil.
(org-export-define-derived-backend 'md): Add new option
`:md-link-mathjax' to control the export of equation links.  Its value
is set to that of the new customization variable `org-md-link-mathjax'.
(org-md-link-mathjax): Add customization variable to enable export to
MathJax "\eqref" (disabled by default).
---
 lisp/ox-md.el | 45 +
 1 file changed, 33 insertions(+), 12 deletions(-)

diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index e2a000bd0..575499072 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -70,6 +70,17 @@ The %s will be replaced by the footnote reference itself."
   :version "26.1"
   :package-version '(Org . "9.0"))
 
+ Links
+
+(defcustom org-md-link-mathjax nil
+  "Non-nil means process LaTeX equation links for MathJax.
+
+When non-nil, links to LaTeX equations will be exported to \"\\eqref\"."
+
+  :group 'org-export-md
+  :package-version '(Org . "9.2")
+  :type 'boolean)
+
 
 ;;; Define Back-End
 
@@ -111,7 +122,8 @@ The %s will be replaced by the footnote reference itself."
   :options-alist
   '((:md-footnote-format nil nil org-md-footnote-format)
 (:md-footnotes-section nil nil org-md-footnotes-section)
-(:md-headline-style nil nil org-md-headline-style)))
+(:md-headline-style nil nil org-md-headline-style)
+(:md-link-mathjax nil nil org-md-link-mathjax)))
 
 
 ;;; Filters
@@ -419,17 +431,26 @@ a communication channel."
 	(or (org-element-property :CUSTOM_ID destination)
 		(org-export-get-reference destination info
 	  (_
-	   (let ((description
-		  (or (org-string-nw-p contents)
-		  (let ((number (org-export-get-ordinal destination info)))
-			(cond
-			 ((not number) nil)
-			 ((atom number) (number-to-string number))
-			 (t (mapconcat #'number-to-string number ".")))
-	 (when description
-	   (format "[%s](#%s)"
-		   description
-		   (org-export-get-reference destination info
+   (if (and destination
+(plist-get info :md-link-mathjax)
+(eq 'latex-environment (org-element-type destination))
+(eq 'math (org-latex--environment-type destination)))
+   ;; Caption and labels are introduced within LaTeX
+   ;; environment.  Use "eqref" macro to refer to those in
+   ;; the document.
+   (format "\\eqref{%s}"
+   (org-export-get-reference destination info))
+ (let ((description
+(or (org-string-nw-p contents)
+(let ((number (org-export-get-ordinal destination info)))
+  (cond
+   ((not number) nil)
+   ((atom number) (number-to-string number))
+   (t (mapconcat #'number-to-string number ".")))
+   (when description
+ (format "[%s](#%s)"
+ description
+ (org-export-get-reference destination info)
  ((org-export-inline-image-p link org-html-inline-image-rules)
   (let ((path (let ((raw-path (org-element-property :path link)))
 		(cond ((not (equal "file" type)) (concat type ":" raw-path))
-- 
2.15.1



[O] Two ob-lua versions

2018-02-10 Thread Thibault Marin

Hi maintainers,

I noticed that a recent change added an ob-lua.el file to contrib/lisp/.
Since there is already an ob-lua.el in lisp/, I was wondering if the new
version was adding functionality not supported by the one in lisp/ (it
does not seem to be the case on casual inspection) and if so, whether
they could/should be merged.

Thanks,

thibault



Re: [O] Equation references in HTML export

2018-01-18 Thread Thibault Marin

> To avoid having to hack the code, you could try using the mathtools
> package and ask it to only number equations that are referenced:
>
> \usepackage{mathtools}  
> \mathtoolsset{showonlyrefs}  

Thanks, if there is a mechanism to alter the preamble when creating the
image, that may be a preferable approach.  I'll try to look into this.




Re: [O] Equation references in HTML export

2018-01-17 Thread Thibault Marin

Nicolas Goaziou writes:
> Could you write a short entry in ORG-NEWS to advertise it?
Done in the attached patch.

Thanks

>From 7c59f34ccd19278f10be399645f641b791e7f41b Mon Sep 17 00:00:00 2001
From: thibault 
Date: Wed, 17 Jan 2018 21:08:59 -0600
Subject: [PATCH] ORG-NEWS: Add note about links to equations in HTML export

---
 etc/ORG-NEWS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 67f51401f..5ebfe4e8c 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -102,6 +102,9 @@ document, use =shrink= value instead, or in addition to align:
 #+END_EXAMPLE
 
 ** New features
+*** Add support for links to LaTeX equations in HTML export
+Use MathJax links when enabled (by ~org-html-with-latex~), otherwise
+add a label to the rendered equation.
 *** Org Tempo may used for snippet expansion of structure template.
 See manual and the commentary section in ~org-tempo.el~ for details.
 *** Exclude unnumbered headlines from table of contents
-- 
2.15.1



Re: [O] Equation references in HTML export

2018-01-16 Thread Thibault Marin

Hi, thanks for the review.  Please find attached an updated patch.

> I guess so. OTOH, I assume latex environments are always math
> environments. One can use LaTex export blocks for "regular" LaTeX.
I left the math check in the attached patch for now.  Please let me know
if you would like me to remove it.

> Nitpick: since this is a predicate, it should be named
> `org-html--math-environment-p'.
Done.

> Meanwhile, I think the implementation is a bit convoluted. What about
> the following?
>
> (replace-regexp-in-string
>  "\\`[ \t]*begin{\\([^*]+?\\)}"
>  "\\1*"
>  (replace-regexp-in-string "^[ \t]*end{\\([^*]+?\\)}[ \r\t\n]*\\'"
>"\\1*"
>latex-frag nil nil 1)
>  nil nil 1)
Done.

> IMO, this doesn't deserve to be a function, you can just use something
> like this:
>
> (if (org-string-nw-p label)
> (replace-regexp-in-string "\\`.*"
>   (format "\\&\nlabel{%s}" label)
>   latex-frag)
>   latex-frag)
Done.

Thanks,

thibault

>From c600a62d67decf957e9170cf9f055915bdfae05a Mon Sep 17 00:00:00 2001
From: thibault 
Date: Sun, 7 Jan 2018 03:04:39 -0600
Subject: [PATCH] ox-html.el: Add label and number to equations in HTML export

* lisp/ox-html.el (org-html--wrap-latex-environment): New function
wrapping the content of latex environments in HTML  tags, adding
"id" and equation number.
(org-html--math-environment-p): New function determining if a latex
environment is a math environment.
(org-html-latex-environment): Use `org-html--wrap-latex-environment' to
wrap equation in HTML container (non-MathJax modes).  Make latex
environment unnumbered when compiling equations to images.  Insert latex
label in environment in MathJax mode.
(org-html-link): Calculate equation number limiting counter to equation
environments.  Use eqref for link when using MathJax
(org-html--make-unlabelled-latex-environment): New function to convert
latex math environments to unnumbered versions (e.g. "equation" ->
"equation*").
---
 lisp/ox-html.el | 128 
 1 file changed, 101 insertions(+), 27 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index d242c613c..7b7d52141 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -430,6 +430,19 @@ for the JavaScript code in this tag.
   .footdef  { margin-bottom: 1em; }
   .figure { padding: 1em; }
   .figure p { text-align: center; }
+  .equation-container {
+display: table;
+text-align: center;
+width: 100%;
+  }
+  .equation {
+vertical-align: middle;
+  }
+  .equation-label {
+display: table-cell;
+text-align: right;
+vertical-align: middle;
+  }
   .inlinetask {
 padding: 10px;
 border: 2px solid gray;
@@ -2823,26 +2836,75 @@ INFO is a plist containing export properties."
 			"Creating LaTeX Image..." nil processing-type)
   (buffer-string
 
+(defun org-html--wrap-latex-environment (contents info  caption label)
+  "Wrap CONTENTS string within appropriate environment for equations.
+INFO is a plist used as a communication channel.  When optional
+arguments CAPTION and LABEL are given, use them for caption and
+\"id\" attribute."
+  (format "\n\n%s%s\n"
+  ;; ID.
+  (if (org-string-nw-p label) (format " id=\"%s\"" label) "")
+  ;; Contents.
+  (format "\n%s\n" contents)
+  ;; Caption.
+  (if (not (org-string-nw-p caption)) ""
+(format "\n\n%s\n"
+caption
+
+(defun org-html--math-environment-p (element  info)
+  "Non-nil when ELEMENT is a LaTeX math environment.
+Math environments match the regular expression defined in
+`org-latex-math-environments-re'.
+INFO is a plist used as a communication channel.  This function
+is meant to be used as a predicate for `org-export-get-ordinal' or
+a value to `org-html-standalone-image-predicate'."
+  (string-match-p org-latex-math-environments-re
+  (org-element-property :value element)))
+
+(defun org-html--make-unlabelled-latex-environment (latex-frag)
+  "Change environment in LATEX-FRAG to an unnumbered environment.
+For instance, change an 'equation' environment to 'equation*'."
+  (replace-regexp-in-string
+   "\\`[ \t]*begin{\\([^*]+?\\)}"
+   "\\1*"
+   (replace-regexp-in-string "^[ \t]*end{\\([^*]+?\\)}[ \r\t\n]*\\'"
+			 "\\1*"
+			 latex-frag nil nil 1)
+   nil nil 1))
+
 (defun org-html-latex-environment (latex-environment _contents info)
   "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
   (let ((processing-type (plist-get info :with-latex))
 	(latex-frag (org-remove-indentation
 		 (org-element-property :value latex-environment)))
-	(attributes (org-export-read-attribute :attr_html latex-environment)))
+ 

Re: [O] Equation references in HTML export

2018-01-10 Thread Thibault Marin

Hi,


> You may be right. In this case, we may use \eqref if MathJax is
> going to be used (like your initial patch did), and do the above
> otherwise.

OK, I think that would work.  To summarize, here are the different
outputs under MathJax and the other modes:

- MathJax mode:
  - Environment:
,
| \begin{align}
| \label{eq:org19c7f92}
| 1 + 1 = 0
| \end{align}
`
  - Link:
,
| link to \eqref{eq:org19c7f92}
`
- other modes, e.g. verbatim: (it is similar for the rest: dvipng,
  imagemagick, etc).:
  - Environment
,
| 
| 
| \begin{align}
| 1 + 1 = 0
| \end{align}
| 
| 
| 
| 1
| 
| 
`
  - Link:
,
| link to equation 1
`

The attached patch produces this on my test cases.

About the CSS caption:
> I'm not sure. Have you checked how captions in other parts of
> "ox-html.el"?

I looked at other structures:
- for figures, the caption is in a `figcaption' tag if HTML5 is used or
  in a paragraph, both under the figure,
- for tables, the caption is in a `caption' tag, at the top or bottom of
  the environment depending on `:html-table-caption-above',
- As far as I can tell, source blocks get no caption.

Since there does not appear to have a common convention, I think the
proposed output (see above with "equation-container", "equation" and
"equation-label" tags) would be fine, if nobody objects.  Some CSS puts
the label on the right side, as with LaTeX export or MathJax.  This only
applies to the non-MathJax modes.


> Do we need to rely on `org-latex-caption-above', which is LaTeX
> specific? We could instead extend `org-html-table-caption-above' to
> handle LaTeX environments, and rename it `org-html-caption-above'.

I think I misunderstood what the caption does in ox-latex.  Here, in the
MathJax case, just I need to insert the `\label' inside the latex
environment, e.g. `\begin{equation}\label{org21321}' similar to what
`org-latex-latex-environment' does.  The caption itself (the equation
number) is always on the right of the equation, regardless of the mode
(MathJax or other), so this is variable is not needed anymore.


I hope the patch looks better now.  I have a few remaining questions:

- The `org-html--is-math-environment' function relies on
  `org-latex-math-environments-re' from ox-latex for the numbering
  (numbering only equations, ignoring other environments).  Is it
  acceptable?
- In non-MathJax modes, I currently pre-process the latex environment to
  change equation environments to their * version,
  e.g. "\begin{equation}" -> "\begin{equation*}".  This is to prevent
  the latex environment from adding its own labeling to the rendered
  image.  This feels like a hack.  Is there a better way to achieve
  this?
- The `org-html--insert-latex-environment-label' (the function that
  inserts `\label' inside the environment also feels like a hack.  I
  originally wanted to re-use the equivalent latex code, but maybe this
  is simpler.  Do you think we can do better?
- In the image modes (e.g. dvipng), I removed the following comment: ";;
  Do not provide a caption or a name to be consistent with `mathjax'
  handling."  I am not sure what it means and whether I should be
  concerned about it.
- I think I have been with messing this file enough now that I should
  add tests.  I didn't see any tests for ox-latex or ox-html.  Is there
  a reason for that?


Please let me know if you have any comment.

Thanks,

thibault
>From 70f6e350615922007e08eec7deecdcdeadd0dc04 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Sun, 7 Jan 2018 03:04:39 -0600
Subject: [PATCH] ox-html.el: Add label and number to equations in HTML export

* lisp/ox-html.el (org-html--wrap-latex-environment): New function
wrapping the content of latex environments in HTML  tags, adding
"id" and equation number.
(org-html--is-math-environment): New function determining if a latex
environment is a math environment.
(org-html-latex-environment): Use `org-html--wrap-latex-environment' to
wrap equation in HTML container (non-MathJax modes).  Make latex
environment unnumbered when compiling equations to images.  Insert latex
label in environment in MathJax mode.
(org-html-link): Calculate equation number limiting counter to equation
environments.  Use eqref for link when using MathJax
(org-html--make-unlabelled-latex-environment): New function to convert
latex math environments to unnumbered versions (e.g. "equation" ->
"equation*").
(org-html--insert-latex-environment-label): Insert latex \label inside
environment.
---
 lisp/ox-html.el | 136 +---
 1 file changed, 109 insertions(+), 27 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index a3a7c5f92..0bb3eff0e 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -430,6 +430,18 @@ for the JavaScript code in this tag.
   .footdef  { margin-bottom: 1em; }
   .figure { padding: 1em; }
   

Re: [O] Equation references in HTML export

2018-01-07 Thread Thibault Marin

Hi, thank you for the review.

> I'm not convinced that inserting label and, more importantly,
> caption within the environment is the way to go. For example, that
> will not work when `org-html-with-latex' is set `verbatim'. Couldn't
> we simply wrap a HTML label and caption above, or below, the whole
> environment so it DTRT in all cases?

It is true that my patch did not address the verbatim mode, I was
focusing on the MathJax output.  The reason I initially decided to rely
on MathJax is that I thought it would be better to take advantage of
MathJax support for LaTeX label and references.  It was then sufficient
to delegate rendering of the latex-environment and links to ox-latex,
although I ended with some unpleasant code to achieve that.

To make sure I understand the desired HTML output, do you mean that
instead of producing this HTML:
,
| \begin{align}
| \label{eq:orgbfedefe}
| 1 + 1 = 0
| \end{align}
`
and relying on MathJax to manage references, we should produce something
like the following?
,
| 
| \begin{align}
| 1 + 1 = 0
| \end{align}
| 
| 
`

Am I understanding correctly?

The advantage of this approach is that it is consistent with how the
other types of references (figures, source blocks, etc.) are managed and
it should work with the verbatim mode.

I have a few questions about the "caption" (i.e. the equation number):

1. Where should it be placed?  In a `' tag like it is done for
   figures?  Ideally, I would like to have the caption (i.e. the
   equation number) on the right side of the equation, as it is done in
   LaTeX, should this be done with CSS?  Should there be a user option
   for the position of the caption?
2. Should we disable MathJax's equation numbering and replace it with
   ours?  I am afraid this may break the setup of users already relying
   on MathJax to label and reference equations.
3. Should there be an option to customize the formatting of the equation
   number, both on the right of the equation itself and in links
   (e.g. wrap the number between parentheses, as `\eqref' dose)?

The attached patch tries to implement some version of this approach.
The code looks less hackish to me, but I still rely on a variable
external to ox-html.el: I use `org-latex-math-environments-re' to
determine if the LaTeX block is a math block; this is used to limit
counters to equations environments, ignoring other types of latex
environments.  Also note that I did not disable MathJax auto-numbering
in the attached patch, so equations have two numbers.

My main concern with this revised version of the patch is the possible
conflicts between MathJax and org equation numbers:
- Only one equation number should be shown, and MathJax and org counters
  may not match (e.g. with multiline equations).
- If we disable MathJax auto-numbering, it seems that we would be losing
  the possibility to have labels on individual lines of multiline
  equations.  Is it true?

Please let me know how you would like me to move forward with this.

Thanks in advance.

thibault

>From 4f57de3208bfe7a86f17c89c15fdc99283701e82 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Sun, 7 Jan 2018 03:04:39 -0600
Subject: [PATCH] ox-html.el: Add label and number to equations in HTML export

* lisp/ox-html.el (org-html--wrap-latex-environment): New function
wrapping the content of latex environments in HTML  tags, adding
"id" and equation number.
(org-html--is-math-environment): New function determining if a latex
environment is a math environment.
(org-html-latex-environment): Use `org-html--wrap-latex-environment' to
wrap equation in HTML container.
(org-html-link): Calculate equation number limiting counter to equation
environments.
---
 lisp/ox-html.el | 57 +
 1 file changed, 53 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 90a6cede0..566f057ac 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -430,6 +430,18 @@ for the JavaScript code in this tag.
   .footdef  { margin-bottom: 1em; }
   .figure { padding: 1em; }
   .figure p { text-align: center; }
+  .equation-container {
+display: table;
+text-align: center;
+width: 100%;
+  }
+  .equation {
+vertical-align: middle;
+  }
+  .equation-label {
+display: table-cell;
+text-align: right;
+  }
   .inlinetask {
 padding: 10px;
 border: 2px solid gray;
@@ -2823,16 +2835,49 @@ INFO is a plist containing export properties."
 			"Creating LaTeX Image..." nil processing-type)
   (buffer-string
 
+(defun org-html--wrap-latex-environment (contents info  caption label)
+  "Wrap CONTENTS string within appropriate environment for equations.
+INFO is a plist used as a communication channel.  When optional
+arguments CAPTION and LABEL are given, use them for caption and
+\"id\" attribute."
+  (format "\n\n%s%s\n"
+  ;; ID.
+  (if (org-string-nw-p label) 

[O] Equation references in HTML export

2018-01-04 Thread Thibault Marin
>From 094df613ec5fd05b6d2124bc45e6f9a8cbef92e5 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Thu, 4 Jan 2018 21:23:59 -0600
Subject: [PATCH] ox-html.el: Add MathJax label and reference to equations in
 HTML export

* lisp/ox-html.el (org-html-format-latex): Add "\label" to latex
environment as done for latex export.  Add optional input
`latex-environment' to trigger the insertion.
(org-html-latex-environment): Pass unprocessed latex-environment to
`org-html-format-latex' when using MathJax.
(org-html-link): Replace rendering of link from "" to
"\ref{}" for equations when using MathJax.


* lisp/ox-latex.el (org-latex--label): Abstract code constructing the
label id into new function.
(org-latex--label-id): New function to construct the label id (used when
inserting labels for latex or html export).
(org-latex--insert-environment-label): New function to insert label into
buffer containing latex environment string (for use in latex and html
export).
(org-latex-latex-environment): Use new function
`org-latex--insert-environment-label' to insert environment label.
---
 lisp/ox-html.el  | 66 +++-
 lisp/ox-latex.el | 70 
 2 files changed, 85 insertions(+), 51 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 90a6cede0..b5257653c 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -180,7 +180,9 @@
 (:creator "CREATOR" nil org-html-creator-string)
 (:with-latex nil "tex" org-html-with-latex)
 ;; Retrieve LaTeX header for fragments.
-(:latex-header "LATEX_HEADER" nil nil newline)))
+(:latex-header "LATEX_HEADER" nil nil newline)
+;; Options for LaTeX environments
+(:latex-caption-above nil nil org-latex-caption-above)))
 
 
 ;;; Internal Variables
@@ -2788,14 +2790,23 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 
  Latex Environment
 
-(defun org-html-format-latex (latex-frag processing-type info)
+(defun org-html-format-latex (latex-frag processing-type info
+	  latex-environment)
   "Format a LaTeX fragment LATEX-FRAG into HTML.
 PROCESSING-TYPE designates the tool used for conversion.  It can
 be `mathjax', `verbatim', nil, t or symbols in
 `org-preview-latex-process-alist', e.g., `dvipng', `dvisvgm' or
 `imagemagick'.  See `org-html-with-latex' for more information.
 INFO is a plist containing export properties."
-  (let ((cache-relpath "") (cache-dir ""))
+  (let* ((cache-relpath "")
+	 (cache-dir "")
+	 (type (when latex-environment
+		 (org-latex--environment-type latex-environment)))
+	 (caption-above-p
+	  (memq type (append (plist-get info :latex-caption-above) '(math
+	 (caption (when (and (eq type 'math)
+			 (eq processing-type 'mathjax))
+		(org-latex--label latex-environment info nil t
 (unless (eq processing-type 'mathjax)
   (let ((bfn (or (buffer-file-name)
 		 (make-temp-name
@@ -2819,6 +2830,8 @@ INFO is a plist containing export properties."
 	(setq latex-frag (concat latex-header latex-frag
 (with-temp-buffer
   (insert latex-frag)
+  (when (and latex-environment caption)
+	(org-latex--insert-environment-label caption caption-above-p))
   (org-format-latex cache-relpath nil nil cache-dir nil
 			"Creating LaTeX Image..." nil processing-type)
   (buffer-string
@@ -2832,7 +2845,8 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	(attributes (org-export-read-attribute :attr_html latex-environment)))
 (cond
  ((memq processing-type '(t mathjax))
-  (org-html-format-latex latex-frag 'mathjax info))
+  (org-html-format-latex latex-frag 'mathjax info
+			 latex-environment))
  ((assq processing-type org-preview-latex-process-alist)
   (let ((formula-link
 	 (org-html-format-latex latex-frag processing-type info)))
@@ -3062,23 +3076,33 @@ INFO is a plist holding contextual information.  See
 	 (format "%s" href attributes desc)))
 	  ;; Fuzzy link points to a target or an element.
 	  (_
-	   (let* ((ref (org-export-get-reference destination info))
-		  (org-html-standalone-image-predicate
-		   #'org-html--has-caption-p)
-		  (number (cond
-			   (desc nil)
-			   ((org-html-standalone-image-p destination info)
-			(org-export-get-ordinal
-			 (org-element-map destination 'link
-			   #'identity info t)
-			 info 'link 'org-html-standalone-image-p))
-			   (t (org-export-get-ordinal
-			   destination info nil 'org-html--has-caption-p
-		  (desc (cond (desc)
-			  ((not number) "No description for this link")
-			  ((numberp number) (number-to-string number))
-			  (t (mapconcat #'number-to-string number ".")
-	 (format "%s" ref attributes desc))
+	   (let* ((processing-type (plist-get info :with-latex))
+		  (latex-environment destination)
+		  (env-type (when (and latex-environment
+   (string=
+	(car latex-environment)

Re: [O] Possible bug with coderef highlighting in HTML export

2017-12-03 Thread Thibault Marin

Hi,

Hi the attach patch fixes the issue for me.  Please let me know if you
have any suggestions.

As always, thanks for the guidance.

thibault


>From a78dc91c9fd1aacb2c65f66ae5afa9ee25f56e01 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Sun, 3 Dec 2017 17:42:13 -0600
Subject: [PATCH] Fix bug in HTML export of code blocks with starting blank
 lines

* lisp/ox-html.el (org-html-do-format-code): Preverse starting blank
  lines when splitting code lines (use `split-string' instead of
  `org-split-string').

  (org-html-fontify-code): Preserve starting blank lines in returned
  code string.
---
 lisp/ox-html.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 0e22c1699..90a6cede0 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2202,7 +2202,7 @@ https://github.com/hniksic/emacs-htmlize;))
 		  (org-html-htmlize-region-for-paste
 		   (point-min) (point-max))
 	  ;; Strip any enclosing  tags.
-	  (let* ((beg (and (string-match "\\`]*>\n*" code) (match-end 0)))
+	  (let* ((beg (and (string-match "\\`]*>\n?" code) (match-end 0)))
 		 (end (and beg (string-match "\\'" code
 	(if (and beg end) (substring code beg end) code)
 
@@ -2215,7 +2215,7 @@ alist between line numbers and references (as returned by
 `org-export-unravel-code'), a boolean specifying if labels should
 appear in the source code, and the number associated to the first
 line of code."
-  (let* ((code-lines (org-split-string code "\n"))
+  (let* ((code-lines (split-string code "\n"))
 	 (code-length (length code-lines))
 	 (num-fmt
 	  (and num-start
-- 
2.14.1



[O] Possible bug with coderef highlighting in HTML export

2017-12-03 Thread Thibault Marin

Hi all,

I am using Org mode version 9.1.3 (release_9.1.3-216-g259656 @
/.../org-mode/lisp/) and I am experiencing an issue with the exported
HTML of the following org file:

,
| this links get highlighted [[(link0)]].
| 
| this link does not get highlighted [[(link1)]].
| 
| #+begin_src emacs-lisp -r
| 0(ref:link0)
| #+end_src
| 
| #+begin_src emacs-lisp -r
| 
| 1(ref:link1)
| #+end_src
`

The relevant HTML output is:

,
| 
| this links get highlighted 1.
| 
| 
| 
| this link does not get highlighted 1.
| 
| 
| 
| 0
| 
| 
| 
| 
| 1
| 
| 
`

The issue is that the link to the line in the second source block is not
highlighted (it does not get the "coderef-off" span markup).

I tried to dig a little and it appears that `org-html-do-format-code' does not
handle empty lines at the beginning of a block.  `(org-split-string "\n1")'
returns '("1") which looses the first empty line.  The line reference received
via the `refs' variable (which has value ((2 . link1))) then becomes out of sync
with the `code' variable (split by lines) used for formatting of the code block.

I am not sure what is the best way to handle this:

1. Should the `refs' variable be built accounting for the top empty lines?
2. Alternatively, should the `org-html-do-format-code' and
   `org-export-format-code' functions count the number of top empty lines and
   adjust the line number accordingly?
3. Should top empty lines be completely deleted, before the `refs' array is
   built?

I can try to propose a patch if the best option can be decided.  Option 2 seems
relatively simple but feels like a hack.

I would appreciate any suggestions on how to best fix this.

Thanks in advance.

thibault



Re: [O] Running org-mode (and emacs) inside the Web browser ?

2017-10-28 Thread Thibault Marin

Hi, org-mode in a browser would be great indeed.

With https://github.com/paradoxxxzero/butterfly, you can get a terminal
in the browser, then run emacs in terminal mode.  It is not ideal (some
keyboard shortcuts are intercepted by the browser), but it seems quite
interesting.

Olivier Berger writes:

> Hi.
>
> I've had this crazy idea to try and "port" emacs to the Web browser
> (using some tools like [[https://browsix.org/][browsix]]), for the
> purpose of running org-mode inside a browser tab.
>
> Anyone having had the same idea yet ?
>
> Interestingly, porting a C program to browsix currently seem to rely on
> emscripten and LLVM... which might not be the best toolchain for
> building Gnu Emacs... but trolls aside, I'd be curious of the
> feasability.
>
> I'm not exactly sure why that would be worth doing... but I can imagine
> running that Emacs Web browser port over some kind of versioned file
> system, and Emacs conf files (org + tangling, of course), so that you
> have "your" org-mode at hand from anywhere using a URL and a browser
> tab... of course, using a keyboard for browsing that tab would be better
> than a touch screen, re keyboard shortcuts.
>
> Any clues ?
>
> I've already spotted http://www.ymacs.org/ which could be of use, for
> the terminal interface parts.
>
> Maybe browsix already provides everything else that's needed (LLVM,
> emscripten, ...).
>
> Another option could be some kind of use of WebAssembly port, for
> browser compatibility, maybe.
>
> Of course performance would be interesting to benchmark.
>
> Thanks for your feedback.
>
> Best regards,



Re: [O] Tangling org file with nested org source block

2017-10-20 Thread Thibault Marin

Following-up on the issue I reported some time ago with tangling of
nested source blocks, I would like to propose a patch for review.

Before the patch, the following file:

,
| #+PROPERTY: header-args :tangle output.org
| 
| #+BEGIN_SRC org
| 
| ,* Test
| 
| ,#+BEGIN_SRC org
| ,,#+BEGIN_SRC emacs-lisp
| '(1 2 3)
| ,,#+END_SRC
| ,#+END_SRC
| 
| #+END_SRC
`

is tangled to:

, output.org
| * Test
| 
| #+BEGIN_SRC org
| #+BEGIN_SRC emacs-lisp
| '(1 2 3)
| #+END_SRC
| #+END_SRC
`

which misses the escaping (commas) for the inner source block.

Tangling after applying the proposed patch results in:

, output.org
| * Test
| 
| #+BEGIN_SRC org
| ,#+BEGIN_SRC emacs-lisp
| '(1 2 3)
| ,#+END_SRC
| #+END_SRC
`

which is properly escaped.

The patch also contains a simple test to validate tangling of nested
blocks.

Could this be considered for a merge?

Thanks in advance

thibault

>From 6300856f8b9623b1ac0a40b7fe62751805159558 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Fri, 20 Oct 2017 22:20:35 -0500
Subject: [PATCH] ob-tangle.el: Fix tangling of org block with nested source
 block

* lisp/ob-tangle.el (org-babel-tangle-single-block): Prevent double unescaping
of source block by removing unnecessary call to `org-unescape-code-in-string'.

* testing/lisp/test-ob-tangle.el (ob-tangle/nested-block) New function.  Test
tangle of org block with nested source block.
---
 lisp/ob-tangle.el  |  7 +++
 testing/lisp/test-ob-tangle.el | 25 +
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index adc680676..09d011fc3 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -494,10 +494,9 @@ non-nil, return the full association list to be used by
 		  link)
 		source-name
 		params
-		(org-unescape-code-in-string
-		 (if org-src-preserve-indentation
-		 (org-trim body t)
-		   (org-trim (org-remove-indentation body
+		(if org-src-preserve-indentation
+		(org-trim body t)
+		  (org-trim (org-remove-indentation body)))
 		comment)))
 (if only-this-block
 	(list (cons src-lang (list result)))
diff --git a/testing/lisp/test-ob-tangle.el b/testing/lisp/test-ob-tangle.el
index 06a73f063..73b75323e 100644
--- a/testing/lisp/test-ob-tangle.el
+++ b/testing/lisp/test-ob-tangle.el
@@ -197,6 +197,31 @@ another block
   (org-babel-tangle-jump-to-org)
   (buffer-string)))
 
+(ert-deftest ob-tangle/nested-block ()
+  "Test tangling of org file with nested block."
+  (should
+   (string=
+"#+begin_src org
+,#+begin_src emacs-lisp
+1
+,#+end_src
+#+end_src
+"
+(org-test-with-temp-text-in-file
+"#+header: :tangle \"test-ob-tangle.org\"
+#+begin_src org
+,#+begin_src org
+,,#+begin_src emacs-lisp
+1
+,,#+end_src
+,#+end_src
+#+end_src"
+  (unwind-protect
+  (progn (org-babel-tangle)
+ (with-temp-buffer (insert-file-contents "test-ob-tangle.org")
+   (buffer-string)))
+(delete-file "test-ob-tangle.org"))
+
 (provide 'test-ob-tangle)
 
 ;;; test-ob-tangle.el ends here
-- 
2.14.1



[O] Tangling org file with nested org source block

2017-09-27 Thread Thibault Marin

Hi list,

I am trying to tangle the following org file:

,
| #+PROPERTY: header-args :tangle output.org
| 
| #+BEGIN_SRC org
| 
| ,* Test
| 
| ,#+BEGIN_SRC org
| ,,#+BEGIN_SRC emacs-lisp
| '(1 2 3)
| ,,#+END_SRC
| ,#+END_SRC
| 
| #+END_SRC
`

(note the double commas at the beginning of the inner-most block).
I am working on master (Org mode version 9.1.1 (release_9.1.1-79-g731e1c.dirty @
.../org-mode/lisp/)), and I get the following:

, output.org
| * Test
| 
| #+BEGIN_SRC org
| #+BEGIN_SRC emacs-lisp
| '(1 2 3)
| #+END_SRC
| #+END_SRC
`

The inner block does not get escaped which causes issues when exporting.  Trying
to investigate this, I ended up in the ~org-babel-tangle-single-block~ function
in =ob-tangle.el=.  The second comma is removed by a call to
~org-unescape-code-in-string~ (l. 497).  Since the incoming string has already
been cleaned-up (i.e. the first comma removed) at that point I wonder why this
call is necessary.  When I remove that call to ~org-unescape-code-in-string~,
tangling produces the output I expect:

, output.org
| * Test
| 
| #+BEGIN_SRC org
| ,#+BEGIN_SRC emacs-lisp
| '(1 2 3)
| ,#+END_SRC
| #+END_SRC
`

where the inner source block is properly escaped.

So, is the call to ~org-unescape-code-in-string~ required?  Does anyone know if
there is a way to get the desired output?

Thanks in advance,
thibault



Re: [O] Variables in properties no longer working

2017-04-12 Thread Thibault Marin

Hi,

The syntax has changed in org-9, see
http://orgmode.org/manual/Header-arguments-in-Org-mode-properties.html#Header-arguments-in-Org-mode-properties

The following seems to fix your example:

:HEADER-ARGS: :var  foo="bar"

Andreas Mueller writes:

> Hello
>
> The attached example seems to be broken with latest org from ELPA
> (org-20170210).
>
> I can reproduce it with an empty emacs config - it works with org
> 8.2.10, but when I install org-20170210 I get "Symbol's value as
> variable is void: foo".
>
> Thanks & best regards, Andreas




Re: [O] plantuml export (unable to resolve link: nil)

2016-12-30 Thread Thibault Marin
Prabhakaran Kasinathan  writes:

> PlantUML src when exported to latex, has problems with link reference. 
>
> export in latex : C-x C-e l l 
> Error: Unable to resolve link: nil
> 
> Fix: #+OPTION: broken-links:mark
>
> Everything works very well with org 8.2.3. How to fix this problem in new
> versions of ORG?
>
> Org src:
>
> #+OPTION: broken-links:mark
>
> * TEST Figure
> Figure [[fig:plantuml]]. 
>
> #+BEGIN_SRC plantuml :file test.png
> A -> B : request
> B -> A : response
> #+END_SRC 
>
> #+NAME: fig:plantuml
> #+CAPTION: Plantuml Test Figure
> #+RESULTS:
>
> Output in ORG v 8.2.3
>
> 
> 
> Latex output:
> 
> 
> 
> 
> #+BEGIN_SRC latex
> 
> 
> \section{TEST figure}
> 
> 
> \label{sec-1}
> 
> 
> 
> 
> 
> 
> Figure \ref{fig:plantuml}. 
> 
> 
> 
> 
> 
> 
> \begin{figure}[htb]
> 
> 
> \centering
> 
> 
> \includegraphics{test.png}
> 
> 
> \caption{\label{fig:plantuml}Plantuml Test Figure}
> 
> 
> \end{figure}
> 
> 
> \end{document}
> 
> 
> #+END_SRC 
>
> Output in ORG 9.0.3
>
> 
> 
> Latex output:
> 
> 
> 
> #+BEGIN_SRC latex
> 
> \section{TEST figure}
> 
> \label{sec:org3dff397}
> 
> 
> 
> 
> Figure [BROKEN LINK: nil]. 
> 
> 
> 
> 
> \begin{center}
> 
> \includegraphics{test.png}
> 
> \end{center}
> 
> #+END_SRC 
> 
> 
> Thanks in advance. 

It works (for me) if I execute the source block before exporting, which
inserts a [[file:]] line (I also find it useful to name the source block
and the #+RESULTS line).  The information in (info "(org) Exporting code
blocks") may be of some help.

thibault



Re: [O] [ANN] Substantial changes to sitemap generation

2016-12-19 Thread Thibault Marin

Nicolas Goaziou writes:

> Hello,
>
> I just pushed a revamp of sitemap generation during publishing process.
> If you tweaked sitemap, you almost certainly need to update your
> settings.
>
> Basically, the changes at the property level are:
>
>   - :sitemap-sans-extension and :sitemap-file-entry-format were removed
>   - :sitemap-function changed its signature
>   - :sitemap-format-entry was added
>
> Also, the patch set implements the following function
>
>   `org-publish-find-property'
>
> See `org-publish-project-alist' for details (or the manual).
>
> Feedback welcome. Ideally, if it is better, we might want to propagate
> the same kind of change to index generation.
>
> Regards,

Hi,

Thanks for pushing the sitemap change, it still works for me (from the
sitemap-wip branch).  I am able to generate a list of posts from the
sitemap and #+INCLUDE it in other pages.

However, I initially got an error when running =make=, there seems to be
a typo in l. 14542 of org.texi ("@cod{" should be "@code{"):
http://orgmode.org/cgit.cgi/org-mode.git/tree/doc/org.texi#n14542

Thanks again.

thibault




Re: [O] Add preamble support to ob-plantuml.el

2016-12-10 Thread Thibault Marin
Hi,

Please find attached a patch updating ORG-NEWS.

Thanks,
thibault

>From 3d335b093d4e95b14cc71317d2aef024f1c64fd5 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Sat, 10 Dec 2016 08:27:48 -0600
Subject: [PATCH] * etc/ORG-NEWS: Header arguments support for PlantUML source
 blocks

---
 etc/ORG-NEWS | 5 +
 1 file changed, 5 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index b6b3123..c115cf9 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -82,6 +82,11 @@ Where clue > 0
 ,#+END_SRC
 #+end_example
 
+ PlantUML: add support for header arguments
+
+[[http://plantuml.com/][Plantuml]] source blocks now support the [[http://orgmode.org/manual/prologue.html#prologue][~:prologue~]], [[http://orgmode.org/manual/epilogue.html#epilogue][~:epilogue~]] and
+[[http://orgmode.org/manual/var.html#var][~:var~]] header arguments.
+
 *** New variable : ~org-bibtex-headline-format-function~
 This allow to use a different title than entry title.
 *** Horizontal rules are no longer ignored in LaTeX table math mode
-- 
2.9.3



Re: [O] Add preamble support to ob-plantuml.el

2016-12-09 Thread Thibault Marin
-babel-execute-src-block'."
 			(org-babel-process-file-name out-file)
 (unless (file-exists-p org-plantuml-jar-path)
   (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
-(with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
+(with-temp-file in-file (insert full-body))
 (message "%s" cmd) (org-babel-eval cmd "")
 nil)) ;; signal that output has already been written to file
 
diff --git a/testing/lisp/test-ob-plantuml.el b/testing/lisp/test-ob-plantuml.el
new file mode 100644
index 000..794d313
--- /dev/null
+++ b/testing/lisp/test-ob-plantuml.el
@@ -0,0 +1,73 @@
+;;; test-ob-plantuml.el --- tests for ob-plantuml.el
+
+;; Copyright (c) 2016 Thibault Marin
+;; Authors: Thibault Marin
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+(unless (featurep 'ob-plantuml)
+  (signal 'missing-test-dependency "Support for PlantUML code blocks"))
+
+(ert-deftest test-ob-plantuml/single-var ()
+  "Test file output with input variable."
+  (should
+   (string=
+"@startuml
+!define CLASSNAME test_class
+class CLASSNAME
+@enduml"
+(let ((org-plantuml-jar-path nil))
+  (org-test-with-temp-text
+	  "#+name: variable_value
+: test_class
+
+#+header: :file tmp.puml
+#+header: :var CLASSNAME=variable_value
+#+begin_src plantuml
+class CLASSNAME
+#+end_src"
+(org-babel-next-src-block)
+	(let ((src-block-info (cdr (org-babel-get-src-block-info
+	  (org-babel-plantuml-make-body
+	   (car src-block-info)
+	   (car (cdr src-block-info)
+
+
+(ert-deftest test-ob-plantuml/prologue ()
+  "Test file output with prologue."
+  (should
+   (string=
+"@startuml
+skinparam classBackgroundColor #FF
+class test_class
+@enduml"
+(let ((org-plantuml-jar-path nil))
+  (org-test-with-temp-text
+	  "#+header: :file tmp.puml
+#+header: :prologue skinparam classBackgroundColor #FF
+#+begin_src plantuml
+class test_class
+#+end_src"
+(org-babel-next-src-block)
+	(let ((src-block-info (cdr (org-babel-get-src-block-info
+	  (org-babel-plantuml-make-body
+	   (car src-block-info)
+	   (car (cdr src-block-info)
+
+(provide 'test-ob-plantuml)
+
+;;; test-ob-plantuml.el ends here
-- 
2.9.3



Re: [O] Add preamble support to ob-plantuml.el

2016-12-06 Thread Thibault Marin
 
diff --git a/testing/lisp/test-ob-plantuml.el b/testing/lisp/test-ob-plantuml.el
new file mode 100644
index 000..794d313
--- /dev/null
+++ b/testing/lisp/test-ob-plantuml.el
@@ -0,0 +1,73 @@
+;;; test-ob-plantuml.el --- tests for ob-plantuml.el
+
+;; Copyright (c) 2016 Thibault Marin
+;; Authors: Thibault Marin
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+(unless (featurep 'ob-plantuml)
+  (signal 'missing-test-dependency "Support for PlantUML code blocks"))
+
+(ert-deftest test-ob-plantuml/single-var ()
+  "Test file output with input variable."
+  (should
+   (string=
+"@startuml
+!define CLASSNAME test_class
+class CLASSNAME
+@enduml"
+(let ((org-plantuml-jar-path nil))
+  (org-test-with-temp-text
+	  "#+name: variable_value
+: test_class
+
+#+header: :file tmp.puml
+#+header: :var CLASSNAME=variable_value
+#+begin_src plantuml
+class CLASSNAME
+#+end_src"
+(org-babel-next-src-block)
+	(let ((src-block-info (cdr (org-babel-get-src-block-info
+	  (org-babel-plantuml-make-body
+	   (car src-block-info)
+	   (car (cdr src-block-info)
+
+
+(ert-deftest test-ob-plantuml/prologue ()
+  "Test file output with prologue."
+  (should
+   (string=
+"@startuml
+skinparam classBackgroundColor #FF
+class test_class
+@enduml"
+(let ((org-plantuml-jar-path nil))
+  (org-test-with-temp-text
+	  "#+header: :file tmp.puml
+#+header: :prologue skinparam classBackgroundColor #FF
+#+begin_src plantuml
+class test_class
+#+end_src"
+(org-babel-next-src-block)
+	(let ((src-block-info (cdr (org-babel-get-src-block-info
+	  (org-babel-plantuml-make-body
+	   (car src-block-info)
+	   (car (cdr src-block-info)
+
+(provide 'test-ob-plantuml)
+
+;;; test-ob-plantuml.el ends here
-- 
2.9.3



Re: [O] Add preamble support to ob-plantuml.el

2016-12-05 Thread Thibault Marin

Hi, thanks for the feedback.

> You don't need to use the TINYCHANGE string since you signed FSF papers
> already.
Fixed.

> The :version keyword is inaccurate. It should be :version "25.2". It is
> also missing :package-version and :safe #'stringp.
Fixed (I hope).

> OOC, what is your use case?
I use it to define common skin options (http://plantuml.com/skinparam)
for all the plantuml blocks in an org file.  I don't know if there is a
better way to that.

Thanks,

thibault


>From 55edfde3636a9e558fe6ca1099477611a2f3ed0f Mon Sep 17 00:00:00 2001
From: thibault 
Date: Mon, 5 Dec 2016 15:46:46 -0600
Subject: [PATCH] ob-plantuml.el: Add preamble to PlantUML source block

* lisp/ob-plantuml.el (org-babel-execute:plantuml) Include preamble
  given by the new `org-plantuml-preamble' customization variable.
---
 lisp/ob-plantuml.el | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-plantuml.el b/lisp/ob-plantuml.el
index 9ce65a9..d73a04b 100644
--- a/lisp/ob-plantuml.el
+++ b/lisp/ob-plantuml.el
@@ -46,6 +46,14 @@
   :version "24.1"
   :type 'string)
 
+(defcustom org-plantuml-preamble ""
+  "Preamble added at the top of every plantuml source block."
+  :group 'org-babel
+  :version "25.2"
+  :package-version '(Org . "9.1")
+  :safe #'stringp
+  :type 'string)
+
 (defun org-babel-execute:plantuml (body params)
   "Execute a block of plantuml code with org-babel.
 This function is called by `org-babel-execute-src-block'."
@@ -85,7 +93,8 @@ This function is called by `org-babel-execute-src-block'."
 			(org-babel-process-file-name out-file)
 (unless (file-exists-p org-plantuml-jar-path)
   (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
-(with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
+(with-temp-file in-file (insert (concat "@startuml\n" org-plantuml-preamble
+	"\n" body "\n@enduml")))
 (message "%s" cmd) (org-babel-eval cmd "")
 nil)) ;; signal that output has already been written to file
 
-- 
2.9.3



[O] Add preamble support to ob-plantuml.el

2016-12-01 Thread Thibault Marin

Hi list,

I am attaching a patch adding support for preamble commands to
ob-plantuml.el.  The string content of the `org-plantuml-preamble'
variable is added at the beginning of each source block before execution
(after the "@startuml" string).

Does this look like this could be merged?  Please let me know if the
patch needs changes.

Thanks,

thibault

>From 157181893c212fea29986c8b072d4f087e4ace24 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Thu, 1 Dec 2016 22:50:32 -0600
Subject: [PATCH] ob-plantuml.el: Add preamble to PlantUML source block

* lisp/ob-plantuml.el (org-babel-execute:plantuml) Include preamble
  given by the new `org-plantuml-preamble' customization variable.

TINYCHANGE
---
 lisp/ob-plantuml.el | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-plantuml.el b/lisp/ob-plantuml.el
index 9ce65a9..6463585 100644
--- a/lisp/ob-plantuml.el
+++ b/lisp/ob-plantuml.el
@@ -46,6 +46,12 @@
   :version "24.1"
   :type 'string)
 
+(defcustom org-plantuml-preamble ""
+  "Preamble added at the top of every plantuml source block."
+  :group 'org-babel
+  :version "24.1"
+  :type 'string)
+
 (defun org-babel-execute:plantuml (body params)
   "Execute a block of plantuml code with org-babel.
 This function is called by `org-babel-execute-src-block'."
@@ -85,7 +91,8 @@ This function is called by `org-babel-execute-src-block'."
 			(org-babel-process-file-name out-file)
 (unless (file-exists-p org-plantuml-jar-path)
   (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
-(with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
+(with-temp-file in-file (insert (concat "@startuml\n" org-plantuml-preamble
+	"\n" body "\n@enduml")))
 (message "%s" cmd) (org-babel-eval cmd "")
 nil)) ;; signal that output has already been written to file
 
-- 
2.9.3



Re: [O] project website from org

2016-11-19 Thread Thibault Marin

Hi,

I recently research that a little.  I think a good place to start is the
worg tutorial at:
http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html.

I decided to use org without jekyll to avoid intermediaries, but that is
one option.

I found the following blog posts about blogging in org useful:

http://bastibe.de/2013-11-13-blogging-with-emacs.html
http://emacs-doctor.com/blogging-from-emacs.html

http://endlessparentheses.com/how-i-blog-one-year-of-posts-in-a-single-org-file.html
https://github.com/howardabrams/dot-files/blob/master/emacs-blog.org
http://www.john2x.com/blog/blogging-with-orgmode.html
https://ogbe.net/blog/blogging_with_org.html
http://nicolas.petton.fr/blog/blogging-with-org-mode.html

and mine:
https://thibaultmarin.github.io/blog/posts/2016-11-13-Personal_website_in_org.html

Hope it helps.

thibault


Julian M. Burgos writes:

> Dear list,
>
> I have given the task to set up a website to display the research in one
> of our projects.  I have little experience with html and website
> maintenance, so I think this would be a good opportunity to learn.  I
> would like to create the content for the website in org-mode (of
> course).  Do you have any recommendations for tools to generate a static
> website from org-mode?  Is a combo of Jekyll and GitHub pages a good
> option?
>
> Many thanks,
>
> Julian




Re: [O] Multiple bibliography files with ox-bibtex and html export

2016-11-15 Thread Thibault Marin

Hi,

I am trying to get back to the multiple bibliography issue discussed
some time ago.

I have two patches proposing two slightly different approaches (from
earlier suggestions):

- 0001-contrib-lisp-ox-bibtex.el-org-bibtex-process-bib-fil.patch creates a
  new bibliography file, a concatenation of all the input files, before calling
  bibtex2html.

- 0001-ox-bibtex.el-Support-multiple-bib-files-in-HTML-expo.patch use
  `start-process' to start the bibtex2html process, then feeds it the input
  bibliography files via stdin.  Once all files are sent it uses a while loop to
  wait for the process to complete (I don't know if there is a better way to do
  that without busy waiting).
  #+BEGIN_SRC emacs-lisp
;; FIXME: How to wait for process to finish?
(while (not process-complete)
  (accept-process-output bibtex2html-proc)
  (sit-for 1)))
  #+END_SRC

Could you please let me know which direction would be preferred, and if changes
should be made to the patch?

Thanks

thibault

>From f093490a3631d4e9de0b18dc5e129eb8049975bc Mon Sep 17 00:00:00 2001
From: thibault 
Date: Tue, 6 Sep 2016 22:42:39 -0500
Subject: [PATCH] * contrib/lisp/ox-bibtex.el (org-bibtex-process-bib-files):
 Add support for multiple bibliography files with html export.

Combine comma-separated bibliography files into a single one and process
it using bibtex2html.  This matches the behavior already present for
latex export.
---
 contrib/lisp/ox-bibtex.el | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el
index 56dec38..b46cb76 100644
--- a/contrib/lisp/ox-bibtex.el
+++ b/contrib/lisp/ox-bibtex.el
@@ -191,13 +191,27 @@ Return new parse tree."
 		(file (org-bibtex-get-file keyword))
 		temp-file
 		out-file)
+	(let ((files (split-string file ",")))
+	  (when (< 1 (length files))
+		(let ((combined-bib-file
+		   (concat
+			(file-name-sans-extension
+			 (file-name-nondirectory
+			  (buffer-file-name))) "-combined.bib")))
+		  (with-temp-file combined-bib-file
+		(dolist (bib files)
+		  (insert-file-contents
+		   (if (equal (file-name-extension bib) "bib")
+			   bib
+			 (concat bib ".bib")
+		  (setq file combined-bib-file
 	;; Test if filename is given with .bib-extension and strip
 	;; it off. Filenames with another extensions will be
 	;; untouched and will finally rise an error in bibtex2html.
 	(setq file (if (equal (file-name-extension file) "bib")
 			   (file-name-sans-extension file) file))
-	;; Outpufiles of bibtex2html will be put into current working directory
-	;; so define a variable for this.
+	;; Output files of bibtex2html will be put into current
+	;; working directory so define a variable for this.
 	(setq out-file (file-name-sans-extension
 			(file-name-nondirectory file)))
 	;; limit is set: collect citations throughout the document
-- 
2.9.3

>From c3056a453efb8bdd39e1dfd6fe4f75090cd1a584 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Tue, 27 Sep 2016 22:36:57 -0500
Subject: [PATCH] ox-bibtex.el: Support multiple bib files in HTML export

* contrib/lisp/ox-bibtex.el (org-bibtex-process-bib-files): Pass
input bibliography files to asynchronous bibtex2html process.
---
 contrib/lisp/ox-bibtex.el | 69 +--
 1 file changed, 49 insertions(+), 20 deletions(-)

diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el
index 56dec38..ca7839f 100644
--- a/contrib/lisp/ox-bibtex.el
+++ b/contrib/lisp/ox-bibtex.el
@@ -188,18 +188,26 @@ Return new parse tree."
   (lambda (keyword)
 	(when (equal (org-element-property :key keyword) "BIBLIOGRAPHY")
 	  (let ((arguments (org-bibtex-get-arguments keyword))
-		(file (org-bibtex-get-file keyword))
+		(files (split-string (org-bibtex-get-file keyword) ","))
 		temp-file
 		out-file)
 	;; Test if filename is given with .bib-extension and strip
-	;; it off. Filenames with another extensions will be
+	;; it off. Filenames with another extensions will be
 	;; untouched and will finally rise an error in bibtex2html.
-	(setq file (if (equal (file-name-extension file) "bib")
-			   (file-name-sans-extension file) file))
-	;; Outpufiles of bibtex2html will be put into current working directory
-	;; so define a variable for this.
-	(setq out-file (file-name-sans-extension
-			(file-name-nondirectory file)))
+	(setq files
+		  (mapcar
+		   (lambda (file)
+		 (if (equal (file-name-extension file) "bib")
+			 (file-name-sans-extension file)
+		   file))
+		   files))
+	;; Output files of bibtex2html will be put into current
+	;; working directory so define a variable for this.
+	(setq out-file
+		  (if (> (length files) 1)
+		  (concat (buffer-file-name) "-combined")
+		  (file-name-sans-extension
+		   (file-name-nondirectory (car files)
 	

Re: [O] Use headings in sitemap

2016-10-31 Thread Thibault Marin

> I think this is a genuine bug. Exclude regexp should be matched against
> relative file names, not absolute ones. I fixed it in wip-sitemap. You
> may want to rebase the branch if you want to experiment with the fix.

The latest update works for me (all my previously reported issues are
fixed).  I have also tested anti-chronologically sorting, which works
too.

Please let me know if you'd like me to run additional tests.

Thanks.




Re: [O] Use headings in sitemap

2016-10-31 Thread Thibault Marin

> I'm not sure to understand. Why resulting in an empty file list is
> a problem? Is there an error in the new "ox-publish.el"?

Sorry for the confusion, I don't think anything is wrong with the new
ox-publish.el, but the selection of excluded files by regexp seems to
have changed (I personally have no problem with this change, I just
thought I'd mention it).

My directory structure has a "website/org/" component so the loose
regexp "website.org" used for exclusion matched any file path (it
appears that full paths are used to determine which files should be
excluded), so, for instance, "/path/to/website/org/index.org" was
excluded, which I do not want.

The same loose regexp did not exclude "index.org" in the previous
version of the sitemap functions. Maybe the exclude regexp was applied
to file names relative to root ("index.org" in my example)?

With a more restrictive regexp "website\\.org", everything behaves as
expected.

I hope it is clearer.

Thanks.



Re: [O] Use headings in sitemap

2016-10-30 Thread Thibault Marin
Nicolas Goaziou writes:

> I pushed an implementation of that idea in wip-sitemap branch, if anyone
> wants to test it.

Thanks!

> For example, setting :sitemap-function property to
>
>(lambda (title list)
>  (concat "#+TITLE: " title "\n\n"
>  (org-list-to-subtree list)))
>
> mostly achieves what the OP wants.

I don't have the `directory-name-p' function (I am still on emacs 24),
so I made a simplistic one: (string= file (file-name-sans-extension
file)), it seems to be sufficient for my test-case.  I don't know if not
being on 25 will cause other issues.

I also had to add a call to `expand-file-name' around the definition of
the `root' variable (in `org-publish-sitemap') to account for the fact
that my :base-directory is defined with "~/" instead of "/home/...".

Another thing I had to modify was the :exclude pattern which was
mis-formed earlier ("setup.org\\|website.org\\|rss.org" changed to
"setup\\.org\\|website\\.org\\|rss\\.org").  The earlier version of the
pattern results in an empty file list but was not a problem on the older
version of the sitemap tools.  Anyway, I have now fixed my setup.

> Also, setting :sitemap-format-entry
> to
>
>(lambda (entry root style)
>  (if (directory-name-p entry)
>  (file-name-nondirectory (directory-file-name entry))
>(format
> "[[file:%s][%s]]%s"
> (file-relative-name entry root)
> (org-publish-find-title entry)
> (let ((subtitle
>(org-element-interpret-data
> (org-publish-find-property entry :subtitle 'latex
>   (if (equal subtitle "") "" (format " (%s)" subtitle))

This is perfect for me, thanks.  I wanted to display the date along with
the title for all the pages in the posts heading so I used the following
(I should be able to filter the folder name better than this, this was
just to test things out).

   (lambda (entry root style)
 (if (directory-name-p entry)
 (file-name-nondirectory (directory-file-name entry))
   (format
"[[file:%s][%s%s]]"
(file-relative-name entry root)
(let ((date
   (org-element-interpret-data
(org-publish-find-property entry :date
  (if (or (equal date "")
  (not (string-match
"posts/"
(file-relative-name entry root
  "" (format "(%s) "
 (replace-regexp-in-string
  "[<>]" ""
  date
(org-publish-find-title entry

> Feedback weclome.

>From my limited use, this perfectly fits my needs.  The only thing I
have not fully tested yet is the sorting mechanism, I'll try that soon.

Thanks,
thibault



Re: [O] replying to emai with org-mode syntax in mu4e

2016-10-28 Thread Thibault Marin

I believe you can add a hook to `'mu4e-compose-mode-hook'.

something like the following (not tested) may work:

(add-hook 'mu4e-compose-mode-hook
  (defun do-compose-stuff ()
  "My settings for message composition."
  (org-mu4e-compose-org-mode)))

Matt Price writes:

> On Fri, Oct 28, 2016 at 7:48 PM, Thibault Marin <thibault.ma...@gmx.com>
> wrote:
>
>>
>> It looks like you may be looking for `org-mu4e-compose-org-mode'.
>>
>
>   duh...
>
> Thank you. So, if I want this to be on by default, do you happen to know
> where I should add a hook?
>
> Really appreciate the help,
> m




Re: [O] replying to emai with org-mode syntax in mu4e

2016-10-28 Thread Thibault Marin

It looks like you may be looking for `org-mu4e-compose-org-mode'.

Matt Price writes:

> I've just switched to mu4e. It's unbelievably great, thank you everyone
> who's recommended it over the years.
>
> However, I would like to compose my replies in org-mode and send them out
> as HTML.  I guess the older tools for doing this are officially deprecated.
> Nonetheless, does anyone use them? Would you be willing to share your
> workflow, and thoughts about what pain points you still have?? I see John
> K. has written some cool posts about, e.g., sending headings out, but not
> about org-ifying the compose buffer.
>
> Thank you!
> Matt




Re: [O] Export tangle filename with source block

2016-10-12 Thread Thibault Marin

Thibault Marin writes:
> OK, then it looks like I may be able to build a list of source block
> name/tangle filename pairs on pre-processing, store it in a global
> variable and use it when processing source-blocks.  It is probably a
> little hack-ish but that would be fine for me.  On my initial attempt,
> `org-babel-tangle-collect-blocks' seems to be skipping blocks on one of
> my tests, but I haven't spent much time on it yet, I'll report back.
It's now working, thanks again for the guidance.

thibault



Re: [O] Use headings in sitemap

2016-10-11 Thread Thibault Marin

Nicolas Goaziou writes:
> This reminds me of a patch Rasmus (Cc'ed) is working on (thread starting
> at: ).
I missed that for some reason, it is better and more ambitious.

> I suggest to let :sitemap-function operate on the lists of files
> included in the sitemap (i.e., the list of files in the project),
> already ordered, and formatted according to
> `org-publish-sitemap-file-entry-format'.
>
> The list would be provided in the same format as the return value from
> `org-list-to-lisp', so that, e.g., `org-list-to-subtree' can be directly
> called on it.
That sounds good to me.

> Also, I suggest to make `org-publish-sitemap-file-entry-format'
> a function instead of a string, so as to get more power, i.e., to not
> limit ourselves to the list of placeholders allowed in the format
> string. In particular, we could provide a public function
> org-publish-get-keyword (file keyword  backend), much like what
> Rasmus does in his patchset, but with a back-end so as to get the value
> of any export keyword. Also, this would make
> `org-publish-sitemap-dir-entry-format' unnecessary.
>
> Eventually, we could run a hook at the end of `org-publish-org-sitemap',
> which would now always be called, in order to give the opportunity to
> modify the sitemap as a whole (e.g., the title).
>
> In a nutshell, ISTM that it would solve both your request and the
> difficulties encountered by Rasmus in changes.
>
> WDYT?
I think it would definitely address my needs and clearly improve the
overall process.  I'll need some time to digest this as I am not too
familiar with the process, but please let me know how I can help with
this (implementation and testing).

Thanks.
thibault



Re: [O] Export tangle filename with source block

2016-10-11 Thread Thibault Marin

Thanks for your reply, it is very helpful.

Nicolas Goaziou writes:
> They are not. You may want to see how cache is used with info in, e.g.,
> `org-export-get-footnote-definition'.
That looks like what I was trying to achieve (except better), thanks.

> The buffer used during export is unlikely to be the same as the original
> one. Macros are expanded, comments are removed and Babel code is
> possibly evaluated. The only hook run in an exact copy of the original
> buffer is `org-export-before-processing-hook'. You can collect anything
> here, but INFO doesn't exist yet.

OK, then it looks like I may be able to build a list of source block
name/tangle filename pairs on pre-processing, store it in a global
variable and use it when processing source-blocks.  It is probably a
little hack-ish but that would be fine for me.  On my initial attempt,
`org-babel-tangle-collect-blocks' seems to be skipping blocks on one of
my tests, but I haven't spent much time on it yet, I'll report back.

Thanks again for the help.
Best,
thibault



Re: [O] Export tangle filename with source block

2016-10-08 Thread Thibault Marin


Hi all,

I am following up on a question I posted here a while ago to show my progress in
case it can help others and to ask for a few clarifications.  I would appreciate
any feedback.

My goal is to add a label to source blocks on HTML export to indicate the name
of the file to which the block is tangled.

The issues originally raised were:
1) How to display the label in HTML export?
2) How to get the tangle file name, which may come from
   1) a file property (e.g. #+PROPERTY: header-args :tangle file-main.py in the
  file header),
   2) a section property (e.g. :header-args: :tangle file-prop.py in a property
  drawer),
   3) the source block header line (e.g. #+BEGIN_SRC python :tangle no)?

It appears that the best way to achieve this is to define a derived backend with
special handling for src-block objects as in
http://orgmode.org/manual/Advanced-configuration.html.

* Example file

Here is the example file I am working with.

#+BEGIN_SRC org
,#+TITLE: Test
,#+PROPERTY: header-args :tangle file-main.py

,#+NAME: src-no-1
,#+BEGIN_SRC python :tangle no
# SHOULD NOT BE TANGLED (1)
,#+END_SRC

,#+NAME: src-header
,#+BEGIN_SRC python :tangle file-header.py
# Tangle to file-header.py
,#+END_SRC

,#+NAME: src-main
,#+BEGIN_SRC python
# Tangle to file-main.py
,#+END_SRC

,* section
  :PROPERTIES:
  :header-args: :tangle file-prop.py
  :END:

,#+NAME: src-prop
,#+BEGIN_SRC python :tangle file-prop.py
# Tangle to file-prop.py
,#+END_SRC

,#+NAME: src-no-2
,#+BEGIN_SRC python :tangle no
# SHOULD NOT BE TANGLED (2)
,#+END_SRC
#+END_SRC


* Formatting the label

I think I have a satisfactory (at least for me) solution for this: in my
src-block exporter I first pass the src-block by the regular HTML exporter:
#+BEGIN_SRC emacs-lisp
(let ((export-out (org-export-with-backend 'html src-block contents info)))
  ...)
#+END_SRC

Later, I add a HTML "" block under the "" block for the source.  I do
this using a regexp:
#+BEGIN_SRC emacs-lisp
(let ((src-start-pat "\\(]+>\\)"))
  (setq export-out
(replace-regexp-in-string
 src-start-pat
 (concat "\\1"
 tang "") export-out)))
#+END_SRC

This adds the label on the bottom right corner of the "" block and uses the
"src-label" class, which can be customized via CSS.


* Getting the tangle filename

I am working with the assumption that this will be done from my src-block
handling function in the derived backend:
#+BEGIN_SRC emacs-lisp
(defun my-html-src-block (src-block contents info)
  ...)

(org-export-define-derived-backend 'my-html 'html
  :translate-alist '((src-block . my-html-src-block)))
#+END_SRC

I run the following code to perform the export using my new backend:
#+BEGIN_SRC emacs-lisp
(org-export-to-file 'my-html (buffer-file-name))
#+END_SRC

*Question 1*: Is the `org-element-src-block-parser' function supposed to resolve
 the tangle filename (including inheritance, i.e. to handle the 3 :tangle
 sources listed above)?

>From the docstring, it would appear that it shouldn't return a :tangle keyword
and that the tangling functions are responsible for choosing the output tangle
file for each block.  Is this correct?

Hoping that my understanding of *Question 1* is correct, I tried to use the
`org-babel-tangle-single-block' and `org-babel-tangle-collect-blocks' functions,
which are used during the actual tangling, to get the tangle filename.

** Working version

Here is what I was able to get to work on my simple example:

#+BEGIN_SRC emacs-lisp

(defun my-html-src-block (src-block contents info)
  "Transcode a SRC-BLOCK element from Org to HTML.
 CONTENTS is nil.  INFO is a plist used as a communication
 channel."
  (let* ((src-block-name (org-element-property :name src-block))
 (src-blocks
  (cdr (car (org-babel-tangle-collect-blocks
 tang
 (export-out (org-export-with-backend 'html src-block contents info)))
(dolist (src-coll src-blocks)
  (when (string= (nth 3 src-coll) src-block-name)
(setq tang (cdr (assoc :tangle (nth 4 src-coll))
(if (and tang (> (length tang) 0) (not (string= tang "no")))
(let ((src-start-pat "\\(]+>\\)"))
  (setq export-out
(replace-regexp-in-string
 src-start-pat
 (concat "\\1"
 tang "") export-out
  export-out))

#+END_SRC

To summarize:
- Collect all the tangled blocks
- Among these, find the one currently passed as input (match by source block
  name)
- Get the :tangle property from the matching collected source-block

The main problem I see which this approach is that it collects all the source
blocks for each src-block entry to process.  This makes the exporting process
slow.

Another issue is that this requires named blocks, but this constraint is
acceptable for me.


** Improvements (which I cannot get to work)

- Add collected blocks to `info' in order to perform the collection only once
  and re-use it for subsequent 

[O] Preserving links when using org-element-interpret-data

2016-10-05 Thread Thibault Marin

Hi all,

I am trying to use the org-element tools to modify an org file from elisp code
and I was wondering if the `org-element-parse-buffer' /
`org-element-interpret-data' combo should result in the same content as the
original buffer.  I am having issues with links where the target and the
description are both =file:= entries.

My original org looks like this:

#+NAME: org-data
#+begin_example
,#+TITLE: test

[[file:a.png][file:a.png]]
#+end_example

The elisp code parses the org file and outputs the result from
`org-element-interpret-data':

#+NAME: org-interpret
#+BEGIN_SRC emacs-lisp :var org-data=org-data :results verbatim

(let (org-tree)
  (with-temp-buffer
(insert org-data)
(setq org-tree (org-element-parse-buffer)))
  (org-element-interpret-data org-tree))

#+END_SRC

#+RESULTS: org-interpret
: "#+TITLE: test
: 
: [[file:a.png][[[file:a.png
: "

The input link is transformed from
#+begin_example
[[file:a.png][file:a.png]]
#+end_example
to
#+begin_example
[[file:a.png][[[file:a.png
#+end_example

Are the additional brackets in the description expected?  Is there any way to
achieve what I want: I am trying to get org-element-interpret-data to output the
same link syntax as the input (in my real application, I am changing the
filename).

Thanks in advance for the help.


P.S.: Here is my version information:
#+BEGIN_SRC emacs-lisp :results drawer
(concat (emacs-version) "\n"
(replace-regexp-in-string "@.*)" "@ ... )" (org-version nil t)))
#+END_SRC

#+RESULTS:
:RESULTS:
GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.21.5)
 of 2016-09-05 on trouble, modified by Debian
Org-mode version 8.3.6 (release_8.3.6-1179-ga9ae0e @ ... )
:END:




[O] Use headings in sitemap

2016-09-28 Thread Thibault Marin

Hi list,

I would like to generate a sitemap for a published website and use it to extract
the last few entries in a specific folder to put on the main page.

The site structure looks like:
.
├── index.org
├── posts
│   ├── A.org
│   ├── B.org
│   └── C.org
├── misc
│   ├── page.org
│   └── other-page.org
└── sitemap.org

In index.org, I would have:
#+begin_src org
#+INCLUDE: sitemap.org::*posts :lines "-10" :only-contents t
#+end_src
to include links to the 10 most recent pages in =posts= (I use
:sitemap-sort-files anti-chronologically in the project setup).  If I am not
missing anything, this requires the sitemap.org file to have a =posts= heading,
but the `org-publish-org-sitemap' function only produces a list of pages.

If there is no better way to get this to work, I would like to propose a patch
to `org-publish-org-sitemap' to produce headings in the sitemap file when a new
parameter is passed and non-nil.  The attached patch is my first attempt at it,
it works for my tests.

I would be interested to hear people's opinion on this:
- Is there a better way to achieve what I want?
- Is the proposed patch acceptable?  Any comments would be appreciated.

Thanks in advance.
thibault

>From a9ae0ecc623d2794475f3481765c637447f1ab24 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Wed, 28 Sep 2016 22:47:48 -0500
Subject: [PATCH] ox-publish.el: Option to use headings instead of list in
 sitemap

* list/ox-publish.el (org-publish-org-sitemap): Add an optional
parameter allowing generation of a sitemap composed of headings
instead of list items.
---
 lisp/ox-publish.el | 39 ---
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el
index 14c93b2..ceb0673 100644
--- a/lisp/ox-publish.el
+++ b/lisp/ox-publish.el
@@ -716,15 +716,17 @@ If `:auto-sitemap' is set, publish the sitemap too.  If
 	  ((functionp fun) (funcall fun project-plist
   (org-publish-write-cache-file
 
-(defun org-publish-org-sitemap (project  sitemap-filename)
+(defun org-publish-org-sitemap
+(project  sitemap-filename use-headings)
   "Create a sitemap of pages in set defined by PROJECT.
 Optionally set the filename of the sitemap with SITEMAP-FILENAME.
-Default for SITEMAP-FILENAME is `sitemap.org'."
+Default for SITEMAP-FILENAME is `sitemap.org'.  When USE-HEADINGS
+is nil (default), the sitemap produced is a list, otherwise it
+uses headings."
   (let* ((project-plist (cdr project))
 	 (dir (file-name-as-directory
 	   (plist-get project-plist :base-directory)))
 	 (localdir (file-name-directory dir))
-	 (indent-str (make-string 2 ?\ ))
 	 (exclude-regexp (plist-get project-plist :exclude))
 	 (files (nreverse
 		 (org-publish-get-base-files project exclude-regexp)))
@@ -736,7 +738,18 @@ Default for SITEMAP-FILENAME is `sitemap.org'."
 	 (sitemap-sans-extension
 	  (plist-get project-plist :sitemap-sans-extension))
 	 (visiting (find-buffer-visiting sitemap-filename))
-	 file sitemap-buffer)
+	 file sitemap-buffer
+	 (entry-string
+	  (if use-headings
+	  `((indent . ,(make-string 1 ?*))
+		(char-space . " "))
+	  `((indent . ,(make-string 2 ?\ ))
+		(char-space . " + "
+	 (entry-string-indent (cdr (assq 'indent entry-string)))
+	 (entry-string-char (string-to-char
+			 (substring entry-string-indent 0 1)))
+	 (entry-string-indent-char (cdr (assq 'char-space entry-string)))
+	 (indent-str entry-string-indent))
 (with-current-buffer
 	(let ((org-inhibit-startup t))
 	  (setq sitemap-buffer
@@ -758,7 +771,7 @@ Default for SITEMAP-FILENAME is `sitemap.org'."
  (file-name-directory link)))
 	  (unless (string= localdir oldlocal)
 		(if (string= localdir dir)
-		(setq indent-str (make-string 2 ?\ ))
+		(setq indent-str entry-string-indent)
 		  (let ((subdirs
 			 (split-string
 			  (directory-file-name
@@ -767,16 +780,18 @@ Default for SITEMAP-FILENAME is `sitemap.org'."
 			(subdir "")
 			(old-subdirs (split-string
   (file-relative-name oldlocal dir) "/")))
-		(setq indent-str (make-string 2 ?\ ))
+		(setq indent-str entry-string-indent)
 		(while (string= (car old-subdirs) (car subdirs))
-		  (setq indent-str (concat indent-str (make-string 2 ?\ )))
+		  (setq indent-str (concat indent-str entry-string-indent))
 		  (pop old-subdirs)
 		  (pop subdirs))
 		(dolist (d subdirs)
 		  (setq subdir (concat subdir d "/"))
-		  (insert (concat indent-str " + " d "\n"))
+		  (insert (concat indent-str entry-string-indent-char d "\n"))
 		  (setq indent-str (make-string
-	(+ (length indent-str) 2) ?\ )))
+	(+ (length indent-str)
+	   (length entry-string-indent))
+	entry-string-char)))
 	;; This is common to 'flat and 'tree
 	(let ((entry
 		   (org-publish-format-file-entry
@@ -784,12 +799,14 @@ Default for SITEMAP-FILENAME is `sitemap.org'."
 		  (regexp 

Re: [O] Multiple bibliography files with ox-bibtex and html export

2016-09-27 Thread Thibault Marin

Hi, sorry for the delay, I was away for a while.

> I'd suggest 2 :) But not that I don't use this feature.
>
> It should be easy to unify the code: something along the lines of starting 
> the process, and then looping over bibtex files and sending them one by one 
> to bibtex2html's standard input.
>
> Cheers,
> Clément.

Please find attached a tentative patch using `process-send-string'.  It seems to
work on my test cases, but I don't know how to wait for the bibtex2html process
to finish before processing the output.  I am currently using a while loop (see
l. 96 of the patch or l. 256 of the patched ox-bibtex.el) combined with a
sentinel changing the while condition upon completion.  This seems suboptimal
but I don't know how to achieve that more elegantly.

I still have a few questions:
1. How can I wait on the subprocess to complete after all the bib files have
   been passed via stdin?
2. Why is this approach preferred over concatenating bib files and delegating
   processing to the bibtex2html executable?

Thanks for the help,
thibault

>From 66edb29f79ddcdf90a47cd8626fb9f04167f5997 Mon Sep 17 00:00:00 2001
From: thibault 
Date: Tue, 27 Sep 2016 22:36:57 -0500
Subject: [PATCH] ox-bibtex.el: Support multiple bib files in HTML export

* contrib/lisp/ox-bibtex.el (org-bibtex-process-bib-files): Pass
input bibliography files to asynchronous bibtex2html process.
---
 contrib/lisp/ox-bibtex.el | 69 +--
 1 file changed, 49 insertions(+), 20 deletions(-)

diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el
index 56dec38..ca7839f 100644
--- a/contrib/lisp/ox-bibtex.el
+++ b/contrib/lisp/ox-bibtex.el
@@ -188,18 +188,26 @@ Return new parse tree."
   (lambda (keyword)
 	(when (equal (org-element-property :key keyword) "BIBLIOGRAPHY")
 	  (let ((arguments (org-bibtex-get-arguments keyword))
-		(file (org-bibtex-get-file keyword))
+		(files (split-string (org-bibtex-get-file keyword) ","))
 		temp-file
 		out-file)
 	;; Test if filename is given with .bib-extension and strip
-	;; it off. Filenames with another extensions will be
+	;; it off. Filenames with another extensions will be
 	;; untouched and will finally rise an error in bibtex2html.
-	(setq file (if (equal (file-name-extension file) "bib")
-			   (file-name-sans-extension file) file))
-	;; Outpufiles of bibtex2html will be put into current working directory
-	;; so define a variable for this.
-	(setq out-file (file-name-sans-extension
-			(file-name-nondirectory file)))
+	(setq files
+		  (mapcar
+		   (lambda (file)
+		 (if (equal (file-name-extension file) "bib")
+			 (file-name-sans-extension file)
+		   file))
+		   files))
+	;; Output files of bibtex2html will be put into current
+	;; working directory so define a variable for this.
+	(setq out-file
+		  (if (> (length files) 1)
+		  (concat (buffer-file-name) "-combined")
+		  (file-name-sans-extension
+		   (file-name-nondirectory (car files)
 	;; limit is set: collect citations throughout the document
 	;; in TEMP-FILE and pass it to "bibtex2html" as "-citefile"
 	;; argument.
@@ -216,18 +224,39 @@ Return new parse tree."
  :options
  (append (plist-get arguments :options)
 	 (list "-citefile" temp-file))
-	;; Call "bibtex2html" on specified file.
-	(unless (eq 0 (apply
-			   'call-process
-			   (append '("bibtex2html" nil nil nil)
-   '("-a" "-nodoc" "-noheader" "-nofooter")
-   (let ((style
-	  (org-not-nil
-	   (org-bibtex-get-style keyword
- (and style (list "--style" style)))
-   (plist-get arguments :options)
-   (list (concat file ".bib")
-	  (error "Executing bibtex2html failed"))
+	;; Call "bibtex2html" on specified files.
+	(let ((process-complete nil)
+		  (bibtex2html-proc
+		   (or
+		(apply
+		 'start-process
+		 (append '("bibtex2html" "*bibtex2html-proc*")
+			 '("bibtex2html" "-a" "-nodoc"
+			   "-noheader" "-nofooter")
+			 (let ((style
+(org-not-nil
+ (org-bibtex-get-style keyword
+			   (and style (list "--style" style)))
+			 (plist-get arguments :options)
+			 `("-o" ,out-file)))
+		(error "Unable to start bibtex2html process"
+	  (when bibtex2html-proc
+		(set-process-sentinel
+		 bibtex2html-proc
+		 (lambda (process event)
+		   (when (equal event "finished\n")
+		 (setq process-complete t
+		(dolist (file files)
+		  (let ((file-content
+			 (with-temp-buffer
+			   (insert-file-contents (concat file ".bib"))
+			   (buffer-string
+		(process-send-string bibtex2html-proc file-content)))
+		(process-send-eof bibtex2html-proc))
+	  ;; FIXME: How to wait for process to finish?
+	  (while (not process-complete)
+		(accept-process-output bibtex2html-proc)
+		(sit-for 1)))
 	(and temp-file (delete-file temp-file))
 	;; 

Re: [O] Multiple bibliography files with ox-bibtex and html export

2016-09-13 Thread Thibault Marin

Clément Pit--Claudel writes:

> On 2016-09-06 23:46, Thibault Marin wrote:
>>>> I am attaching a patch which allows me to use multiple files with html
>>>> export.  It creates a combined bibliography file and call bibtex2html on
>>>> it.  I am not sure this is the best way to address this, so any
>>>> suggestion would be welcome.
>
> Sorry for the late comment.  bibtex2html can read from standard input; maybe 
> that would be cleaner?
>
> Clément.

That may be a good idea, it would prevent potential name clashing with
the created bib file.  Currently, the function creates a
-combined.bib file with the content of all
bibliography files, then bibtex2html creates
-combined.html and
-combined_bib.html.  Passing the contents via stdin
would skip the -combined.bib.  We could achieve the
same by simply deleting -combined.bib after calling
bibtex2html.  I personally don't mind leaving the .bib file after
processing, but if there is a consensus to limit the side effect, we can
do that.

As far as the implementation goes, I am not sure what is the best way to
get this to work with stdin.  In the attached patch (which does *not*
work) I tried to use `call-process-region' and dump the bibliography
files into a temporary buffer.  This complicates the code a little.
Alternatively, we could use the `INFILE' parameter from `call-process',
but it looks that this would require a file, so it would not change much
from the previous patch.

Any thoughts?

>From 85369923cdd7540467a615ca92cf486fd6d08708 Mon Sep 17 00:00:00 2001
From: thibault <thibault@dell-desktop.WORKGROUP>
Date: Thu, 8 Sep 2016 22:06:21 -0500
Subject: [PATCH 2/2] * contrib/lisp/ox-bibtex.el
 (org-bibtex-process-bib-files): (WIP)  Add support for multiple bibliography
 files with html export.

Pass multiple bibliography files (comma separated) to bibtex2html.
---
 contrib/lisp/ox-bibtex.el | 82 ++-
 1 file changed, 53 insertions(+), 29 deletions(-)

diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el
index b46cb76..38c0957 100644
--- a/contrib/lisp/ox-bibtex.el
+++ b/contrib/lisp/ox-bibtex.el
@@ -187,24 +187,20 @@ Return new parse tree."
 (org-element-map tree 'keyword
   (lambda (keyword)
 	(when (equal (org-element-property :key keyword) "BIBLIOGRAPHY")
-	  (let ((arguments (org-bibtex-get-arguments keyword))
-		(file (org-bibtex-get-file keyword))
-		temp-file
-		out-file)
-	(let ((files (split-string file ",")))
-	  (when (< 1 (length files))
-		(let ((combined-bib-file
-		   (concat
-			(file-name-sans-extension
-			 (file-name-nondirectory
-			  (buffer-file-name))) "-combined.bib")))
-		  (with-temp-file combined-bib-file
-		(dolist (bib files)
-		  (insert-file-contents
-		   (if (equal (file-name-extension bib) "bib")
-			   bib
-			 (concat bib ".bib")
-		  (setq file combined-bib-file
+	  (let* ((arguments (org-bibtex-get-arguments keyword))
+		 (file (org-bibtex-get-file keyword))
+		 temp-file
+		 out-file
+		 (multiple-bib-files (split-string file ","))
+		 (multiple-bib-p (< 1 (length multiple-bib-files)))
+		 multiple-bib-file)
+	(when multiple-bib-p
+	  (setq multiple-bib-file
+		(concat
+		 (file-name-sans-extension
+		  (file-name-nondirectory
+		   (buffer-file-name))) "-combined.bib"))
+	  (setq file multiple-bib-file))
 	;; Test if filename is given with .bib-extension and strip
 	;; it off. Filenames with another extensions will be
 	;; untouched and will finally rise an error in bibtex2html.
@@ -231,17 +227,45 @@ Return new parse tree."
  (append (plist-get arguments :options)
 	 (list "-citefile" temp-file))
 	;; Call "bibtex2html" on specified file.
-	(unless (eq 0 (apply
-			   'call-process
-			   (append '("bibtex2html" nil nil nil)
-   '("-a" "-nodoc" "-noheader" "-nofooter")
-   (let ((style
-	  (org-not-nil
-	   (org-bibtex-get-style keyword
- (and style (list "--style" style)))
-   (plist-get arguments :options)
-   (list (concat file ".bib")
-	  (error "Executing bibtex2html failed"))
+	(let* ((bibtex2html-cmd '("bibtex2html" nil nil nil))
+		   (bibtex2html-args-default '("-a" "-nodoc" "-noheader"
+	   "-nofooter"))
+		   (bibtex2html-style
+		(let ((style
+			   (org-not-nil
+			(org-bibtex-get-style keyword
+		  (and style (list "--style" style
+		   (bibtex2html-opts (plist-get arguments :options)))
+	  (message "mf=%s file=%s" multiple-bib-file multiple-bib-files)
+	  (if multiple-bib-p
+		  (with-temp-buffer
+		multiple-bib-file
+		(d

Re: [O] Multiple bibliography files with ox-bibtex and html export

2016-09-10 Thread Thibault Marin


Do you mean:
1) Using `call-process' for cases where a single bibliography file is
passed and `process-send-string' when multiple files are used?
2) Using `process-send-string' regardless of the number of bibliography
files?  In this case, can we still unify the code between single and
multiple files?
3) Something else?

In my opinion 1) makes the code more error-prone and harder to
maintain. If there are other reasons to replace the existing behavior
(for single bibliography files) by `process-send-string', then 2) may
make sense, otherwise it sounds to me that it may not be worth it: the
existing code is apparently working fine for single files, I would feel
a little uncomfortable changing it based only on my test case,
especially since there isn't (as far as I know) a battery of tests for
it.

- Is having a temporary file unacceptable?

The first patch creates and keeps the combined bibliography around, but
this created file could easily be deleted if preferred.  If the problem
is just the extra file, the first patch can fix it and seems less
intrusive to me.

- Is the main concern performance?

I think that the main argument for using standard input may be to skip
the disk access required by the temporary file.  I do not know if the
potential savings for files of size around a few MB (or more?) justify
the more intrusive change in the code.  Maybe others would have a better
feel for this than I do.

Thanks for the comments on this.  Once a consensus is reached, I can
work towards an updated patch.

thibault

> I'd suggest starting the process and then using process-send-string.
> 
> Clément.
> 
> On 2016-09-08 23:55, Thibault Marin wrote:
> > 
> > Clément Pit--Claudel writes:
> > 
> >> On 2016-09-06 23:46, Thibault Marin wrote:
> >>>>> I am attaching a patch which allows me to use multiple files with html
> >>>>> export.  It creates a combined bibliography file and call bibtex2html on
> >>>>> it.  I am not sure this is the best way to address this, so any
> >>>>> suggestion would be welcome.
> >>
> >> Sorry for the late comment.  bibtex2html can read from standard input; 
> >> maybe that would be cleaner?
> >>
> >> Clément.
> > 
> > That may be a good idea, it would prevent potential name clashing with
> > the created bib file.  Currently, the function creates a
> > -combined.bib file with the content of all
> > bibliography files, then bibtex2html creates
> > -combined.html and
> > -combined_bib.html.  Passing the contents via stdin
> > would skip the -combined.bib.  We could achieve the
> > same by simply deleting -combined.bib after calling
> > bibtex2html.  I personally don't mind leaving the .bib file after
> > processing, but if there is a consensus to limit the side effect, we can
> > do that.
> > 
> > As far as the implementation goes, I am not sure what is the best way to
> > get this to work with stdin.  In the attached patch (which does *not*
> > work) I tried to use `call-process-region' and dump the bibliography
> > files into a temporary buffer.  This complicates the code a little.
> > Alternatively, we could use the `INFILE' parameter from `call-process',
> > but it looks that this would require a file, so it would not change much
> > from the previous patch.
> > 
> > Any thoughts?
> > 



Re: [O] ob-lua

2016-09-07 Thread Thibault Marin

Hi,

I have received the FSF papers.

Thanks
thibault

Nicolas Goaziou writes:

> Hello,
>
> Thibault Marin <thibault.ma...@gmx.com> writes:
>
>> I have just submitted the FSF papers.
>
> Great! Please let me know when the whole process is done.
>
> Thank you.




Re: [O] Multiple bibliography files with ox-bibtex and html export

2016-09-06 Thread Thibault Marin

Nicolas Goaziou writes:

> Hello,
>
> Thibault Marin <thibault.ma...@gmx.com> writes:
>
>> I would like to use ox-bibtex to export a bibliography to html with
>> multiple bibliography files, as follows:
>>
>> #+BIBLIOGRAPHY: bibtex_1.bib,bibtex_2.bib plain option:-d option:-noabstract 
>> limit:t
>>
>> This works with latex export but not with html (I get a "Executing
>> bibtex2html failed").  It appears that bibtex2html can only process a
>> single file.
>>
>> I am attaching a patch which allows me to use multiple files with html
>> export.  It creates a combined bibliography file and call bibtex2html on
>> it.  I am not sure this is the best way to address this, so any
>> suggestion would be welcome.
>>
>> Does this look like something that could be merged?
>
> Apparently no objection was raised, so I think this can be merged. Some
> minor comments below.
>
>> +(let ((files (org-split-string file ",")))
>
> I think `split-string' is sufficient here.
>
>> +  (when (< 1 (length files))
>> +(let ((combined-bib-file
>> +   (concat
>> +(file-name-sans-extension
>> + (file-name-nondirectory
>> +  (buffer-file-name))) "-combined.bib")))
>> +  (with-temp-file combined-bib-file
>> +(dolist (bib files)
>> +  (insert-file-contents
>> +   (if (equal (file-name-extension bib) "bib")
>> +   bib
>> + (concat bib ".bib")
>> + )
>> +   )
>> +  )
>> +)
>> +  (setq file combined-bib-file)
>> +  )
>> +)
>> +  )
>
> There should be no dangling parenthesis in Lisp.
>
> Could you send an updated patch?
>
> Thank you.
>
>
> Regards,

Thanks for the review, here is an updated patch.

Best,

thibault
>From cb07ff936587a456f1e6599d216efe9463431d3f Mon Sep 17 00:00:00 2001
From: thibault <thibault.ma...@gmx.com>
Date: Tue, 6 Sep 2016 22:42:39 -0500
Subject: [PATCH] * contrib/lisp/ox-bibtex.el (org-bibtex-process-bib-files):
 Add support for multiple bibliography files with html export.

Combine comma-separated bibliography files into a single one and process
it using bibtex2html.  This matches the behavior already present for
latex export.
---
 contrib/lisp/ox-bibtex.el | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el
index 56dec38..b46cb76 100644
--- a/contrib/lisp/ox-bibtex.el
+++ b/contrib/lisp/ox-bibtex.el
@@ -191,13 +191,27 @@ Return new parse tree."
 		(file (org-bibtex-get-file keyword))
 		temp-file
 		out-file)
+	(let ((files (split-string file ",")))
+	  (when (< 1 (length files))
+		(let ((combined-bib-file
+		   (concat
+			(file-name-sans-extension
+			 (file-name-nondirectory
+			  (buffer-file-name))) "-combined.bib")))
+		  (with-temp-file combined-bib-file
+		(dolist (bib files)
+		  (insert-file-contents
+		   (if (equal (file-name-extension bib) "bib")
+			   bib
+			 (concat bib ".bib")
+		  (setq file combined-bib-file
 	;; Test if filename is given with .bib-extension and strip
 	;; it off. Filenames with another extensions will be
 	;; untouched and will finally rise an error in bibtex2html.
 	(setq file (if (equal (file-name-extension file) "bib")
 			   (file-name-sans-extension file) file))
-	;; Outpufiles of bibtex2html will be put into current working directory
-	;; so define a variable for this.
+	;; Output files of bibtex2html will be put into current
+	;; working directory so define a variable for this.
 	(setq out-file (file-name-sans-extension
 			(file-name-nondirectory file)))
 	;; limit is set: collect citations throughout the document
-- 
2.8.1



Re: [O] ob-lua

2016-08-30 Thread Thibault Marin

Thanks,

I have just submitted the FSF papers.

Best,
thibault

Nicolas Goaziou writes:

> Hello,
>
> Thibault Marin <thibault.ma...@gmx.com> writes:
>
>> I am attaching an updated patch adding the Lua language to the CSS in
>> `org-html-style-default'.
>
> Patches applied. Thank you.
>
> Would you consider signing FSF papers if not already done?
>
>
> Regards,




[O] Problem exporting file with code references

2016-08-26 Thread Thibault Marin


Hi list,

I am trying to run the last example on the documentation page:
http://orgmode.org/manual/Literal-examples.html and I am running into a
problem.  The following is the full org file I am trying to export:

---
#+BEGIN_SRC emacs-lisp -n -r
(save-excursion  (ref:sc)
   (goto-char (point-min)))  (ref:jump)
#+END_SRC
In line [[(sc)]] we remember the current position.  [[(jump)][Line
(jump)]] jumps to point-min.
---

When trying to export (I tried html or latex), I get the following error
message: 'user-error: Unable to resolve link: "sc"'.

Trying to investigate, it appears that the `org-babel--normalize-body'
function (ob-core.el) removes the references "(ref:sc)" and "(ref:jump)"
from the code block prior to execution.  This happens during the call to
`org-babel-exp-process-buffer' when `org-export-babel-evaluate' is
non-nil (in ox.el).  From that point, the source block content does not
contain the "(ref:sc)" and "(ref:jump)" text.  Consequently, when
reaching the `org-export-resolve-coderef' function, the link is not
found in the code and the error is returned.

I get this failure with version:
Org-mode version 8.3.5 (release_8.3.5-1079-g61dd51.dirty @
~/org_git/org-mode/lisp/)

For reference, the same file get exported without issue when using an
older version:
Org-mode version 8.3.5 (8.3.5-elpaplus @
~/.emacs.d/elpa/org-plus-contrib-20160815/)

Am I missing something here? Is this a bug?

Any help would be greatly appreciated.

Thanks,
thibault



[O] Multiple bibliography files with ox-bibtex and html export

2016-08-23 Thread Thibault Marin

Hi list,

I would like to use ox-bibtex to export a bibliography to html with
multiple bibliography files, as follows:

#+BIBLIOGRAPHY: bibtex_1.bib,bibtex_2.bib plain option:-d option:-noabstract 
limit:t

This works with latex export but not with html (I get a "Executing
bibtex2html failed").  It appears that bibtex2html can only process a
single file.

I am attaching a patch which allows me to use multiple files with html
export.  It creates a combined bibliography file and call bibtex2html on
it.  I am not sure this is the best way to address this, so any
suggestion would be welcome.

Does this look like something that could be merged?

Thanks,
thibault



>From c8a97a2d79d349a5d7c55ce052daa0794bde49ad Mon Sep 17 00:00:00 2001
From: thibault 
Date: Tue, 23 Aug 2016 22:57:19 -0500
Subject: [PATCH] * contrib/lisp/ox-bibtex.el (org-bibtex-process-bib-files):
 Add support for multiple bibliography files with html export.

Combine comma-separated bibliography files into a single one and process it
using bibtex2html.  This matches the behavior already present for latex export.
---
 contrib/lisp/ox-bibtex.el | 25 +++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el
index 56dec38..7e266ab 100644
--- a/contrib/lisp/ox-bibtex.el
+++ b/contrib/lisp/ox-bibtex.el
@@ -191,13 +191,34 @@ Return new parse tree."
 		(file (org-bibtex-get-file keyword))
 		temp-file
 		out-file)
+	(let ((files (org-split-string file ",")))
+	  (when (< 1 (length files))
+		(let ((combined-bib-file
+		   (concat
+			(file-name-sans-extension
+			 (file-name-nondirectory
+			  (buffer-file-name))) "-combined.bib")))
+		  (with-temp-file combined-bib-file
+		(dolist (bib files)
+		  (insert-file-contents
+		   (if (equal (file-name-extension bib) "bib")
+			   bib
+			 (concat bib ".bib")
+			 )
+		   )
+		  )
+		)
+		  (setq file combined-bib-file)
+		  )
+		)
+	  )
 	;; Test if filename is given with .bib-extension and strip
 	;; it off. Filenames with another extensions will be
 	;; untouched and will finally rise an error in bibtex2html.
 	(setq file (if (equal (file-name-extension file) "bib")
 			   (file-name-sans-extension file) file))
-	;; Outpufiles of bibtex2html will be put into current working directory
-	;; so define a variable for this.
+	;; Output files of bibtex2html will be put into current
+	;; working directory so define a variable for this.
 	(setq out-file (file-name-sans-extension
 			(file-name-nondirectory file)))
 	;; limit is set: collect citations throughout the document
-- 
2.8.1



Re: [O] ob-lua

2016-08-23 Thread Thibault Marin

Hi,

Thibault Marin writes:

>>> The attached patch (using git format-patch) is adding test-ob-lua.el and
>>> ob-lua.el.  My contribution to ob-lua.el is only a tiny patch on top of
>>> Dieter's ob-lua.el but it appears as a new file in the patch, since
>>> ob-lua.el is not currently in the repository.
>>
>> That is not a problem. We can make this appear as two patches.
> OK, should I send two patches then?
>
>>
>>> I am still a bit confused about this (make test complains about a
>>> missing dependency for ob-lua, maybe because it is in contrib/lisp?),
>>> but I can run the test using the command line emacs --batch command
>>> described in testing/README, and it does not require any change to
>>> org-test.el, so I'll run tests this way from now on.
>>
>> The point is to add it to core Org, not to contrib/, isn't it?
> I wasn't sure, attached is a new patch with ob-lua in lisp/.
>
> Thanks,
> thibault

I am attaching an updated patch adding the Lua language to the CSS in
`org-html-style-default'.

If you would like me to make two separate patches, one with the original
ob-lua.el from Dieter Schoen and one with my changes and additions
(test-ob-lua.el and ox-html.el), please let me know.

Thanks,
thibault

>From e79446cda1a8fbf025145f00c0f2c7ba1caaa374 Mon Sep 17 00:00:00 2001
From: thibault <thibault.ma...@gmx.com>
Date: Mon, 22 Aug 2016 10:32:55 -0500
Subject: [PATCH] ob-lua.el: Add lua support to org-babel

* lisp/ob-lua.el: Resurrect ob-lua.el from
https://lists.gnu.org/archive/html/emacs-orgmode/2014-05/msg01149.html,
replace deprecated functions `org-babel-get-header' and
`org-babel-trim' by `org-babel--get-vars' and `org-trim'
respectively.  Sessions are not supported.

* testing/test-ob-lua.el: Testing for ob-lua.el.  Test table
variable passing and results with `value' and `output' options.

* lisp/ox-html.el (org-html-style-default): Add pre.src-lua to css.
---
 lisp/ob-lua.el  | 405 
 lisp/ox-html.el |   1 +
 testing/lisp/test-ob-lua.el | 141 +++
 3 files changed, 547 insertions(+)
 create mode 100644 lisp/ob-lua.el
 create mode 100644 testing/lisp/test-ob-lua.el

diff --git a/lisp/ob-lua.el b/lisp/ob-lua.el
new file mode 100644
index 000..a81ec66
--- /dev/null
+++ b/lisp/ob-lua.el
@@ -0,0 +1,405 @@
+;;; ob-lua.el --- org-babel functions for lua evaluation
+
+;; Copyright (C) 2009-2014 Free Software Foundation, Inc.
+
+;; Authors: Dieter Schoen
+;;	 Eric Schulte, Dan Davison
+;; Keywords: literate programming, reproducible research
+;; Homepage: http://orgmode.org
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;; Requirements:
+;; for session support, lua-mode is needed.
+;; lua-mode is not part of GNU Emacs/orgmode, but can be obtained
+;; from marmalade or melpa.
+;; The source respository is here:
+;; https://github.com/immerrr/lua-mode
+
+;; However, sessions are not yet working.
+
+;; Org-Babel support for evaluating lua source code.
+
+;;; Code:
+(require 'ob)
+(eval-when-compile (require 'cl))
+
+(declare-function org-remove-indentation "org" )
+(declare-function lua-shell "ext:lua-mode" ( argprompt))
+(declare-function lua-toggle-shells "ext:lua-mode" (arg))
+(declare-function run-lua "ext:lua" (cmd  dedicated show))
+
+(defvar org-babel-tangle-lang-exts)
+(add-to-list 'org-babel-tangle-lang-exts '("lua" . "lua"))
+
+(defvar org-babel-default-header-args:lua '())
+
+(defcustom org-babel-lua-command "lua"
+  "Name of the command for executing Lua code."
+  :version "24.5"
+  :package-version '(Org . "8.3")
+  :group 'org-babel
+  :type 'string)
+
+(defcustom org-babel-lua-mode 'lua-mode
+  "Preferred lua mode for use in running lua interactively.
+This will typically be 'lua-mode."
+  :group 'org-babel
+  :version "24.5"
+  :package-version '(Org . "8.3")
+  :type 'symbol)
+
+(defcustom org-babel-lua-hline-to "None"
+  "Replace hlines in incoming tables with this when translating to lua."
+  :group 'org-babel
+  :version "24.5"
+  :package-version '(Org . "8.3")
+  :ty

Re: [O] ob-lua

2016-08-22 Thread Thibault Marin
+ts = ts .. indent .. t2s(k,indent .. \"  \") .. \" = \\n\" ..
+   t2s(v, indent .. \"  \")
+ else
+ts = ts .. indent .. t2s(k,indent .. \"  \") .. \" = \" ..
+   t2s(v, indent .. \"  \") .. \"\\n\"
+ end
+  end
+  return ts
+   else
+  return tostring(t)
+   end
+end
+"
+		  (format "fd:write(_))
+fd:close()"
+			  (org-babel-process-file-name tmp-file 'noquote)))
+	   (list (format "fd=io.open(\"%s\", \"w\")
+fd:write( _ )
+fd:close()"
+			 (org-babel-process-file-name tmp-file
+  'noquote)))
+	 (input-body (lambda (body)
+		   (mapc (lambda (line) (insert line) (funcall send-wait))
+			 (split-string body "[\r\n]"))
+		   (funcall send-wait)))
+ (results
+  (case result-type
+(output
+ (mapconcat
+  #'org-trim
+  (butlast
+   (org-babel-comint-with-output
+   (session org-babel-lua-eoe-indicator t body)
+ (funcall input-body body)
+ (funcall send-wait) (funcall send-wait)
+ (insert org-babel-lua-eoe-indicator)
+ (funcall send-wait))
+   2) "\n"))
+(value
+ (let ((tmp-file (org-babel-temp-file "lua-")))
+   (org-babel-comint-with-output
+   (session org-babel-lua-eoe-indicator nil body)
+ (let ((comint-process-echoes nil))
+   (funcall input-body body)
+   (funcall dump-last-value tmp-file
+(member "pp" result-params))
+   (funcall send-wait) (funcall send-wait)
+   (insert org-babel-lua-eoe-indicator)
+   (funcall send-wait)))
+   (org-babel-eval-read-file tmp-file))
+(unless (string= (substring org-babel-lua-eoe-indicator 1 -1) results)
+  (org-babel-result-cond result-params
+	results
+(org-babel-lua-table-or-string results)
+
+(defun org-babel-lua-read-string (string)
+  "Strip 's from around Lua string."
+  (if (string-match "^'\\([^\000]+\\)'$" string)
+  (match-string 1 string)
+string))
+
+(provide 'ob-lua)
+
+
+
+;;; ob-lua.el ends here
diff --git a/testing/lisp/test-ob-lua.el b/testing/lisp/test-ob-lua.el
new file mode 100644
index 000..d0c1302
--- /dev/null
+++ b/testing/lisp/test-ob-lua.el
@@ -0,0 +1,141 @@
+;;; test-ob-lua.el --- tests for ob-lua.el
+
+;; Copyright (c) 2016 Thibault Marin
+;; Authors: Thibault Marin
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+(unless (featurep 'ob-lua)
+  (signal 'missing-test-dependency "Support for Lua code blocks"))
+
+(ert-deftest test-ob-lua/simple-value ()
+  "Test associative array return by value."
+  (should
+   (= 2
+  (org-test-with-temp-text
+	  "#+name: eg
+| a   | 1 |
+| b   | 2 |
+
+#+header: :results value
+#+header: :var x = eg
+#+begin_src lua
+return x['b']
+#+end_src"
+(org-babel-next-src-block)
+(org-babel-execute-src-block)
+
+(ert-deftest test-ob-lua/simple-output ()
+  "Test text output from table."
+  (should
+   (equal "result: c\n"
+	  (org-test-with-temp-text
+	  "#+name: eg
+| a | b | c | d |
+
+#+header: :results output
+#+header: :var x = eg
+#+begin_src lua
+print('result: ' .. x[1][3])
+#+end_src"
+	(org-babel-next-src-block)
+	(org-babel-execute-src-block)
+
+
+(ert-deftest test-ob-lua/colnames-yes-header-argument ()
+  "Test table passing with `colnames' header."
+  (should
+   (equal "a"
+	  (org-test-with-temp-text
+	  "#+name: eg
+| col |
+|-|
+| a   |
+| b   |
+
+#+header: :colnames yes
+#+header: :var x = eg
+#+begin_src lua
+return x[1]
+#+end_src"
+	(org-babel-next-src-block)
+	(org-babel-execute-src-block)
+
+
+(ert-deftest test-ob-lua/colnames-yes-header-argument-pp ()
+  "Test table passing with `colnames' header and pp option."
+  (should
+   (equal "a = 12\nb = 13\n"
+	  (org-test-with-temp-text
+	  "#+name: eg
+| col | val |
+|-+-|
+| a   |  12 |
+| b   |  13 |
+
+#+header: :results value pp
+#+header: :colnames yes
+#+header: :var x = eg
+#+begin_src lua
+return x
+#+end_src"
+	(org-babel-next-src-block)
+	(org-babel-execute-src-block)
+
+(ert-deftest test-ob-lua/colnames-nil-header-argument ()
+  "Test table with `colnames' set to `nil'."
+  (should
+   (equal "1 = a\n2 = b\n"
+	  (org-test-with-temp-text
+	  "#+name: eg
+| col |
+|-|
+| a   |
+| b   |
+
+#+header: :colnames nil
+#+header: :var x = eg
+#+header: :results value pp
+#+begin_src lua
+return x
+#+end_src"
+	(org-babel-next-src-block)
+	(org-babel-execute-src-block)
+
+(ert-deftest test-ob-lua/colnames-no-header-argument ()
+  "Test table passing without `colnames'."
+  (should
+   (equal "1 = col\n2 = a\n3 = b\n"
+	  (org-test-with-temp-text
+	  "#+name: eg
+| col |
+|-|
+| a   |
+| b   |
+
+#+header: :colnames no
+#+header: :var x = eg
+#+header: :results value pp
+#+begin_src lua
+return x
+#+end_src"
+	(org-babel-next-src-block)
+	(org-babel-execute-src-block)
+
+(provide 'test-ob-lua)
+
+;;; test-ob-lua.el ends here
-- 
2.8.1



Re: [O] ob-lua

2016-08-21 Thread Thibault Marin
;[\r\n]"))
+		   (funcall send-wait)))
+ (results
+  (case result-type
+(output
+ (mapconcat
+  #'org-trim
+  (butlast
+   (org-babel-comint-with-output
+   (session org-babel-lua-eoe-indicator t body)
+ (funcall input-body body)
+ (funcall send-wait) (funcall send-wait)
+ (insert org-babel-lua-eoe-indicator)
+ (funcall send-wait))
+   2) "\n"))
+(value
+ (let ((tmp-file (org-babel-temp-file "lua-")))
+   (org-babel-comint-with-output
+   (session org-babel-lua-eoe-indicator nil body)
+ (let ((comint-process-echoes nil))
+       (funcall input-body body)
+   (funcall dump-last-value tmp-file
+(member "pp" result-params))
+   (funcall send-wait) (funcall send-wait)
+   (insert org-babel-lua-eoe-indicator)
+   (funcall send-wait)))
+   (org-babel-eval-read-file tmp-file))
+(unless (string= (substring org-babel-lua-eoe-indicator 1 -1) results)
+  (org-babel-result-cond result-params
+	results
+(org-babel-lua-table-or-string results)
+
+(defun org-babel-lua-read-string (string)
+  "Strip 's from around Lua string."
+  (if (string-match "^'\\([^\000]+\\)'$" string)
+  (match-string 1 string)
+string))
+
+(provide 'ob-lua)
+
+
+
+;;; ob-lua.el ends here
diff --git a/testing/lisp/test-ob-lua.el b/testing/lisp/test-ob-lua.el
new file mode 100644
index 000..d0c1302
--- /dev/null
+++ b/testing/lisp/test-ob-lua.el
@@ -0,0 +1,141 @@
+;;; test-ob-lua.el --- tests for ob-lua.el
+
+;; Copyright (c) 2016 Thibault Marin
+;; Authors: Thibault Marin
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+(unless (featurep 'ob-lua)
+  (signal 'missing-test-dependency "Support for Lua code blocks"))
+
+(ert-deftest test-ob-lua/simple-value ()
+  "Test associative array return by value."
+  (should
+   (= 2
+  (org-test-with-temp-text
+	  "#+name: eg
+| a   | 1 |
+| b   | 2 |
+
+#+header: :results value
+#+header: :var x = eg
+#+begin_src lua
+return x['b']
+#+end_src"
+(org-babel-next-src-block)
+(org-babel-execute-src-block)
+
+(ert-deftest test-ob-lua/simple-output ()
+  "Test text output from table."
+  (should
+   (equal "result: c\n"
+	  (org-test-with-temp-text
+	  "#+name: eg
+| a | b | c | d |
+
+#+header: :results output
+#+header: :var x = eg
+#+begin_src lua
+print('result: ' .. x[1][3])
+#+end_src"
+	(org-babel-next-src-block)
+	(org-babel-execute-src-block)
+
+
+(ert-deftest test-ob-lua/colnames-yes-header-argument ()
+  "Test table passing with `colnames' header."
+  (should
+   (equal "a"
+	  (org-test-with-temp-text
+	  "#+name: eg
+| col |
+|-|
+| a   |
+| b   |
+
+#+header: :colnames yes
+#+header: :var x = eg
+#+begin_src lua
+return x[1]
+#+end_src"
+	(org-babel-next-src-block)
+	(org-babel-execute-src-block)
+
+
+(ert-deftest test-ob-lua/colnames-yes-header-argument-pp ()
+  "Test table passing with `colnames' header and pp option."
+  (should
+   (equal "a = 12\nb = 13\n"
+	  (org-test-with-temp-text
+	  "#+name: eg
+| col | val |
+|-+-|
+| a   |  12 |
+| b   |  13 |
+
+#+header: :results value pp
+#+header: :colnames yes
+#+header: :var x = eg
+#+begin_src lua
+return x
+#+end_src"
+	(org-babel-next-src-block)
+	(org-babel-execute-src-block)
+
+(ert-deftest test-ob-lua/colnames-nil-header-argument ()
+  "Test table with `colnames' set to `nil'."
+  (should
+   (equal "1 = a\n2 = b\n"
+	  (org-test-with-temp-text
+	  "#+name: eg
+| col |
+|-|
+| a   |
+| b   |
+
+#+header: :colnames nil
+#+header: :var x = eg
+#+header: :results value pp
+#+begin_src lua
+return x
+#+end_src"
+	(org-babel-next-src-block)
+	(org-babel-execute-src-block)
+
+(ert-deftest test-ob-lua/colnames-no-header-argument ()
+  "Test table passing without `colnames'."
+  (should
+   (equal &qu

Re: [O] ob-lua

2016-08-20 Thread Thibault Marin

>> There may be a better way to do it, but it seems to work.
>
> In this case, `org-babel-get-header' should be replaced with
> `org-babel--get-vars', per ORG-NEWS.

Thanks, it is much better.

>> So my question is: could this be considered for a merge?  The code does
>> not seem to support sessions, I am not sure if that should be
>> a blocker.
>
> It isn't a blocker, indeed. Could you send an updated patch? A set of
> tests would be nice, too.

I have updated the patch to use `org-babel--get-vars' as suggested.  I
also have replaced `org-babel-trim' by `org-trim' (as advised in
ORG-NEWS) and replaced the `case' statement by a `pcase' (I used
ob-python.el for reference).  Please let me know if these changes are
acceptable and if other changes are required.

About the test, I am attaching my first attempt at this, please let me
know if you have some advice on how to improve it or if you had
something else in mind.  This is the first time I use ert or org-test,
but these seem to pass and test the basic features.

By the way, when trying to run the tests from emacs, I had an error
message when doing a (require 'org-test): "let: Required feature `ert-x'
was not provided".  Am I doing something wrong?  I worked around it by
(1) installing the `ertx' package and (2) replacing (require 'ert-x) by
(require 'ertx) in org-test.el (that's probably the wrong thing to do,
but it allowed me to run my tests).

Thanks for your help.

thibault



test-ob-lua.el
Description: application/emacs-lisp
132c132
<(mapcar #'cdr (org-babel-get-header params :var
---
>(org-babel--get-vars params)))
292,312c292,312
<  (case result-type
<(output (org-babel-eval org-babel-lua-command
<(concat (if preamble (concat preamble "\n"))
  (pcase result-type
>(`output (org-babel-eval org-babel-lua-command
> (concat (if preamble (concat preamble "\n"))
> 	body)))
>(`value (let ((tmp-file (org-babel-temp-file "lua-")))
> 		 (org-babel-eval
> 		  org-babel-lua-command
> 		  (concat
> 		   (if preamble (concat preamble "\n") "")
> 		   (format
> 			(if (member "pp" result-params)
> 			org-babel-lua-pp-wrapper-method
> 			  org-babel-lua-wrapper-method)
> 			(mapconcat
> 			 (lambda (line) (format "\t%s" line))
> 			 (split-string
> 			  (org-remove-indentation
> 			   (org-trim body))
> 			  "[\r\n]") "\n")
> 			(org-babel-process-file-name tmp-file 'noquote
> 		 (org-babel-eval-read-file tmp-file))
315c315
<   (org-babel-lua-table-or-string (org-babel-trim raw)
---
>   (org-babel-lua-table-or-string (org-trim raw)
369c369
<   #'org-babel-trim
---
>   #'org-trim


[O] ob-lua

2016-08-19 Thread Thibault Marin

Hi list,

I was looking for lua support in source blocks and I came across this
discussion:
https://lists.gnu.org/archive/html/emacs-orgmode/2014-05/msg01149.html.  It
seems that this was never merged, but I am not sure why.

Trying to use the ob-lua.el file linked, it appears to be working for my task (I
just need to be able to pass variables to a lua block).  I only had to make a
small change to the file to get it to work, as `org-babel-get-header' is no
longer available:

132c132
<(mapcar #'cdr (org-babel-get-header params :var
---
>(remove nil (mapcar (lambda (x) (when (eq (car x) :var) (cdr x))) 
> params

There may be a better way to do it, but it seems to work.

So my question is: could this be considered for a merge?  The code does
not seem to support sessions, I am not sure if that should be a blocker.

Thanks,
thibault



[O] Export tangle filename with source block

2016-07-31 Thread Thibault Marin

Hi list,

I have an org file that I am tangling into multiple files, and exporting
to html.  What I would like to do is to label each source block in the
exported html with the filename used for tangling this specific block.
I don't have a strong opinion about the actual appearance of the label
(adding a comment at the top of the source block, hover in the code
textarea, other?).

I couldn't find any option to do that, so I initially though of using
`org-export-filter-src-block-functions' (following
http://orgmode.org/manual/Advanced-configuration.html).  I was not able
to get the org-element object for the current block from the parameter
received by the filter.  It looks like the third parameter (`info') may
have more information but I currently don't see how to get (1) the
current source block, and (2) the tangling filename.

I then tried to define a derived backend with custom handling of source
blocks as described in the documentation.

I currently have the following, where I try to get the tangle filename
using `org-babel-get-src-block-info', and later insert it into the html
content using an ugly regexp.

(defun my-html-src-block (src-block contents info)
  "Transcode a SRC-BLOCK element from Org to HTML.
 CONTENTS is nil.  INFO is a plist used as a communication
 channel."
  (let* ((lang (org-element-property :language src-block))
 (src-info (org-babel-get-src-block-info t src-block))
 (tang (cdr (assq :tangle (nth 2 src-info
 (export-out (org-export-with-backend 'html src-block contents info))
 )
(if (and (string= lang "lua") (and tang (> (length tang) 0)))
(progn
  (let ((src-start-pat "\\(\\)"))
(replace-regexp-in-string src-start-pat
  (concat "\\1"
  "\n-- ["
  tang
  "]\n\n") export-out)
)
  )
  export-out
  )
)
  )

(org-export-define-derived-backend 'my-html 'html
  :translate-alist '((src-block . my-html-src-block)))

Besides feeling wrong, this always gets the tangle name from the top
level org option ("#+PROPERTY: tangle main-file" at the top of the file)
instead of the one overridden by individual blocks "#+BEGIN_SRC :tangle
other-file".  Moreover the added comment is not syntax highlighted and
this feels really wrong.

Does anybody have any idea on how to achieve this?

Thanks in advance.

thibault



[O] [PATCH] EPS generation from latex source block

2016-02-14 Thread Thibault Marin

Here is a small patch I use to produce TikZ EPS files from LaTeX source
blocks.

>From d750c26cabc87e4917974df8080714d5d7e2c9a8 Mon Sep 17 00:00:00 2001
From: thibault
Date: Sun, 14 Feb 2016 03:07:20 -0600
Subject: [PATCH] Add eps output to ob-latex (without imagemagick)
To: emacs-orgmode@gnu.org

* ob-latex: Accept output file with EPS extension without requiring the
  imagemagick option.  This can be used to generate EPS files from TikZ
  in LaTeX source blocks.
* ox-latex: Add `org-latex-eps-process' based on
  `org-latex-pdf-process'.  Default build uses dvips and ghostscript to
  produce an EPS file with correct bounding box.  Add an extra optional
  argument to `org-latex-compile' to pass the output file type (pdf or
  eps)
---
 lisp/ob-latex.el | 18 +++
 lisp/ox-latex.el | 67 +---
 2 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el
index a8fbe29..416e5be 100644
--- a/lisp/ob-latex.el
+++ b/lisp/ob-latex.el
@@ -158,7 +158,7 @@ This function is called by `org-babel-execute-src-block'."
   ".html")
   out-file)
  (error "HTML file produced but SVG file requested")
-((or (string-match "\\.pdf$" out-file) imagemagick)
+((or (string-match "\\.pdf$" out-file) (string-match "\\.eps$" 
out-file) imagemagick)
  (with-temp-file tex-file
(require 'ox-latex)
(insert
@@ -189,9 +189,14 @@ This function is called by `org-babel-execute-src-block'."
 "\n\\end{preview}\n\\end{document}\n")
   (concat "\n\\begin{document}\n" body "\n\\end{document}\n"
   (when (file-exists-p out-file) (delete-file out-file))
- (let ((transient-pdf-file (org-babel-latex-tex-to-pdf tex-file)))
+ (let ((transient-pdf-file
+(cond ((string-match "\\.pdf$" out-file)
+   (org-babel-latex-tex-to-pdf tex-file))
+  ((and (not imagemagick) (string-match "\\.eps$" 
out-file))
+   (org-babel-latex-tex-to-eps tex-file)
(cond
-((string-match "\\.pdf$" out-file)
+((or (string-match "\\.pdf$" out-file)
+ (and (not imagemagick) (string-match "\\.eps$" out-file)))
  (rename-file transient-pdf-file out-file))
 (imagemagick
  (org-babel-latex-convert-pdf
@@ -199,7 +204,7 @@ This function is called by `org-babel-execute-src-block'."
  (when (file-exists-p transient-pdf-file)
(delete-file transient-pdf-file))
  ((string-match "\\.\\([^\\.]+\\)$" out-file)
-  (error "Can not create %s files, please specify a .png or .pdf file 
or try the :imagemagick header argument"
+  (error "Can not create %s files, please specify a .png, .pdf or .eps 
file or try the :imagemagick header argument"
 (match-string 1 out-file
 nil) ;; signal that output has already been written to file
 body))
@@ -216,6 +221,11 @@ This function is called by `org-babel-execute-src-block'."
   (require 'ox-latex)
   (org-latex-compile file))
 
+(defun org-babel-latex-tex-to-eps (file)
+  "Generate a pdf file according to the contents FILE."
+  (require 'ox-latex)
+  (org-latex-compile file nil "eps"))
+
 (defun org-babel-prep-session:latex (_session _params)
   "Return an error because LaTeX doesn't support sessions."
   (error "LaTeX does not support sessions"))
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 9285aac..eb0c883 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1166,6 +1166,36 @@ file name as its single argument."
 ("latexmk -g -pdflatex=\"%latex\" %f"))
  (function)))
 
+(defcustom org-latex-eps-dpi 300
+  "Resolution for EPS image generation.
+This is passed to the ghostscript command when adjusting the bounding
+box."
+  :group 'org-export-latex
+  :type 'integer
+  :version "25.1"
+  :package-version '(Org . "9.0"))
+
+(defcustom org-latex-eps-process
+  '("latex -interaction nonstopmode %f"
+"dvips -R -K0 -E %b.dvi -o %b_t.eps"
+"gs -dNOPAUSE -dBATCH -sDEVICE=eps2write -r600 -sOutputFile=%b.eps 
%b_t.eps")
+  "Commands to process a LaTeX file to an EPS file.
+This is a list of commands built similarly to
+`org-latex-pdf-process'.  %f in the command will be replaced by
+the full file name, %b by the file base name (i.e. without
+directory and extension parts), %o by the base directory of the
+file.
+
+Alternatively, this may be a Lisp function that does the
+processing, so you could use this to apply the machinery of
+AUCTeX or the Emacs LaTeX mode.  This function should accept the
+file name as its single argument."
+  :group 'org-export-pdf
+  :type '((string)
+ (function))
+  :version "25.1"
+  :package-version '(Org . "9.0"))
+
 (defcustom