emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Happily exporting LaTeX, now want to export to text and HTML, can't figure how to handle latex markup
@ 2017-08-02  5:20 Grant Rettke
  2017-08-02 16:15 ` Berry, Charles
  0 siblings, 1 reply; 6+ messages in thread
From: Grant Rettke @ 2017-08-02  5:20 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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

Good morning,

I'm happily exporting an Org-Mode document to LaTeX using the nifty
`letterine' package. An example is attached. Writing using it has been
so fun that naturally now I want to export it both to text and HTML.
My source document looks like this for reference and all of this works
fine:

> start
#+TITLE: A Poem Title
#+AUTHOR:
#+DATE:
#+OPTIONS: num:nil
#+LATEX: \pagenumbering{gobble}

#+BEGIN_CENTER
@@latex:\lettrine[lines=1]{T}{this}@@ is line 1.

@@latex:\lettrine[lines=1]{H}{ere}@@ is line 2.

@@latex:\lettrine[lines=1]{O}{ver}@@ there is line 3.
#+END_CENTER
> end

Now I'm left be wondering how I can using a single document and export
it correctly to LaTeX, HTML and text. Here are some ideas I came up
with:

- Write the same line two times, one for each exporter. Redundant but
it would work.
- Use a source block that takes a line of text, checks the type of
exporter running, and returns an appropriate markup then on export it
works right.
- Maybe there is a macro for this?
- I'm out of ideas

My Internet search results found a lot of answers about easy stuff.
However this article

https://emacs.stackexchange.com/questions/18636/create-a-custom-block-in-org-mode-that-exports-to-latex-and-html

looked interesting. I haven't started coding anything up yet and I
wanted to talk to you before that.

Thank you.

[-- Attachment #2: poem.pdf --]
[-- Type: application/pdf, Size: 12178 bytes --]

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

* Re: Happily exporting LaTeX, now want to export to text and HTML, can't figure how to handle latex markup
  2017-08-02  5:20 Happily exporting LaTeX, now want to export to text and HTML, can't figure how to handle latex markup Grant Rettke
@ 2017-08-02 16:15 ` Berry, Charles
  2017-08-02 23:22   ` Jeremie Juste
  2017-08-07  1:06   ` Grant Rettke
  0 siblings, 2 replies; 6+ messages in thread
From: Berry, Charles @ 2017-08-02 16:15 UTC (permalink / raw)
  To: Grant Rettke; +Cc: emacs-orgmode@gnu.org


> On Aug 1, 2017, at 10:20 PM, Grant Rettke <gcr@wisdomandwonder.com> wrote:
> 
> Good morning,
> 
> I'm happily exporting an Org-Mode document to LaTeX using the nifty
> `letterine' package. An example is attached. Writing using it has been
> so fun that naturally now I want to export it both to text and HTML.
> My source document looks like this for reference and all of this works
> fine:
> 
>> start
> #+TITLE: A Poem Title
> #+AUTHOR:
> #+DATE:
> #+OPTIONS: num:nil
> #+LATEX: \pagenumbering{gobble}
> 
> #+BEGIN_CENTER
> @@latex:\lettrine[lines=1]{T}{this}@@ is line 1.
> 
> @@latex:\lettrine[lines=1]{H}{ere}@@ is line 2.
> 
> @@latex:\lettrine[lines=1]{O}{ver}@@ there is line 3.
> #+END_CENTER
>> end
> 
> Now I'm left be wondering how I can using a single document and export
> it correctly to LaTeX, HTML and text. Here are some ideas I came up
> with:
> 
> - Write the same line two times, one for each exporter. Redundant but
> it would work.
> - Use a source block that takes a line of text, checks the type of
> exporter running, and returns an appropriate markup then on export it
> works right.
> - Maybe there is a macro for this?

Putting together a macro seems like the best option.  Recall that you can use elisp in macros by placing it between `(eval’ and `)', so the following emits “def’ in all but latex exports and “abc” for latex.

#+BEGIN_SRC emacs-lisp
(defun foo (a b) (if (eq 'latex org-export-current-backend) a b))
#+END_SRC


#+MACRO: bar (eval (foo $1 $2))


{{{bar("abc" "def")}}}

HTH,

Chuck


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

* Re: Happily exporting LaTeX, now want to export to text and HTML, can't figure how to handle latex markup
  2017-08-02 16:15 ` Berry, Charles
@ 2017-08-02 23:22   ` Jeremie Juste
  2017-08-03 16:56     ` Berry, Charles
  2017-08-07  1:06   ` Grant Rettke
  1 sibling, 1 reply; 6+ messages in thread
From: Jeremie Juste @ 2017-08-02 23:22 UTC (permalink / raw)
  To: Berry, Charles; +Cc: emacs-orgmode@gnu.org, Grant Rettke



Hello 

>
> Putting together a macro seems like the best option.  Recall that you
> can use elisp in macros by placing it between `(eval’ and `)', so the
> following emits “def’ in all but latex exports and “abc” for latex.
>


Yes I found this nice piece of code  

It switches to svg if backend is html and to raw latex if backend is
latex. You only have to tweak it your needs.

#+header: :file (by-backend (html "tree.svg") (t 'nil))
#+header: :imagemagick
#+header: :results (by-backend (pdf "latex") (t "raw"))
#+begin_src latex
  \usetikzlibrary{trees}
  \begin{tikzpicture}
    \node [circle, draw, fill=red!20] at (0,0) {1}
    child { node [circle, draw, fill=blue!30] {2}
      child { node [circle, draw, fill=green!30] {3} }
      child { node [circle, draw, fill=yellow!30] {4} }};
  \end{tikzpicture}
#+end_src

* COMMENT setup
#+begin_src emacs-lisp :results silent
  (setq org-babel-latex-htlatex "htlatex")
  (defmacro by-backend (&rest body)
    `(case (if (boundp 'backend) (org-export-backend-name backend) nil) ,@body))
#+end_src

The reference http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html


Best regards

Jeremie

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

* Re: Happily exporting LaTeX, now want to export to text and HTML, can't figure how to handle latex markup
  2017-08-02 23:22   ` Jeremie Juste
@ 2017-08-03 16:56     ` Berry, Charles
  2017-08-03 19:16       ` Jeremie Juste
  0 siblings, 1 reply; 6+ messages in thread
From: Berry, Charles @ 2017-08-03 16:56 UTC (permalink / raw)
  To: Jeremie Juste; +Cc: emacs-orgmode@gnu.org, Grant Rettke


> On Aug 2, 2017, at 4:22 PM, Jeremie Juste <jeremiejuste@gmail.com> wrote:
> 
> 
> 
> Hello 
> 
>> 
>> Putting together a macro seems like the best option.  Recall that you
>> can use elisp in macros by placing it between `(eval’ and `)', so the
>> following emits “def’ in all but latex exports and “abc” for latex.
>> 
> 
> 
> Yes I found this nice piece of code  
> 
> It switches to svg if backend is html and to raw latex if backend is
> latex. You only have to tweak it your needs.
> 

I think this is obsolete. It fails on org-9.0.9. What version of org are you using? 

In any case replacing the ~(if ...)~ by ~org-export-current-backend~ will fix it.


> #+header: :file (by-backend (html "tree.svg") (t 'nil))
> #+header: :imagemagick
> #+header: :results (by-backend (pdf "latex") (t "raw"))
> #+begin_src latex
>  \usetikzlibrary{trees}
>  \begin{tikzpicture}
>    \node [circle, draw, fill=red!20] at (0,0) {1}
>    child { node [circle, draw, fill=blue!30] {2}
>      child { node [circle, draw, fill=green!30] {3} }
>      child { node [circle, draw, fill=yellow!30] {4} }};
>  \end{tikzpicture}
> #+end_src
> 
> * COMMENT setup
> #+begin_src emacs-lisp :results silent
>  (setq org-babel-latex-htlatex "htlatex")
>  (defmacro by-backend (&rest body)
>    `(case (if (boundp 'backend) (org-export-backend-name backend) nil) ,@body))
> #+end_src
> 
> The reference http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html
> 

Another case were adding dates to Worg entries might help.

Chuck

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

* Re: Happily exporting LaTeX, now want to export to text and HTML, can't figure how to handle latex markup
  2017-08-03 16:56     ` Berry, Charles
@ 2017-08-03 19:16       ` Jeremie Juste
  0 siblings, 0 replies; 6+ messages in thread
From: Jeremie Juste @ 2017-08-03 19:16 UTC (permalink / raw)
  To: Berry, Charles; +Cc: emacs-orgmode@gnu.org, Grant Rettke

"Berry, Charles" <ccberry@ucsd.edu> writes:
Hello, 

Thanks for the update
>> 
>
> I think this is obsolete. It fails on org-9.0.9. What version of org are you using? 
>
> In any case replacing the ~(if ...)~ by ~org-export-current-backend~ will fix it.
>
>

> Another case were adding dates to Worg entries might help.

will keep that in mind.


Best regards,

Jeremie

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

* Re: Happily exporting LaTeX, now want to export to text and HTML, can't figure how to handle latex markup
  2017-08-02 16:15 ` Berry, Charles
  2017-08-02 23:22   ` Jeremie Juste
@ 2017-08-07  1:06   ` Grant Rettke
  1 sibling, 0 replies; 6+ messages in thread
From: Grant Rettke @ 2017-08-07  1:06 UTC (permalink / raw)
  To: Berry, Charles; +Cc: emacs-orgmode@gnu.org

On Wed, Aug 2, 2017 at 11:15 AM, Berry, Charles <ccberry@ucsd.edu> wrote:
>> On Aug 1, 2017, at 10:20 PM, Grant Rettke <gcr@wisdomandwonder.com> wrote:
>>
>> I'm happily exporting an Org-Mode document to LaTeX using the nifty
>> `letterine' package. An example is attached. Writing using it has been
> Putting together a macro seems like the best option.  Recall that you can use elisp in macros by placing it between `(eval’ and `)', so the following emits “def’ in all but latex exports and “abc” for latex.
>
> #+BEGIN_SRC emacs-lisp
> (defun foo (a b) (if (eq 'latex org-export-current-backend) a b))
> #+END_SRC
>
>
> #+MACRO: bar (eval (foo $1 $2))
>
>
> {{{bar("abc" "def")}}}

Thank you. That helps a lot.

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

end of thread, other threads:[~2017-08-07  1:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-02  5:20 Happily exporting LaTeX, now want to export to text and HTML, can't figure how to handle latex markup Grant Rettke
2017-08-02 16:15 ` Berry, Charles
2017-08-02 23:22   ` Jeremie Juste
2017-08-03 16:56     ` Berry, Charles
2017-08-03 19:16       ` Jeremie Juste
2017-08-07  1:06   ` Grant Rettke

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).