emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Tangled Latex code gives error
@ 2015-04-26 23:20 Lawrence Bottorff
  2015-04-27  1:45 ` Lawrence Bottorff
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Lawrence Bottorff @ 2015-04-26 23:20 UTC (permalink / raw)
  To: emacs-orgmode

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

I'm following the Latex howto of org-mode babel. Here's the snippet from
the howto I've got in a separate .org file (see bottom of howto page):

#+LATEX_HEADER: \usepackage{tikz}

First execute the second code block, to define the convenience macro
and to set the required new variables in ob-latex.el.  Then export to
HTML and to pdf to see the tree exported as an SVG image and as
embedded tikz respectively.

* Tikz test
Here's a tree, exported to both html and pdf.

#+header: :file (by-backend (html "tree.svg") (t 'nil))
#+header: :imagemagick
#+header: :results (by-backend (pdf "latex") (t "raw"))
#+header: :tangle yes
#+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
#+header: :tangle yes
#+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

This doesn't really produce a .svg of the tree as advertised, but exporting
to Latex does produce it just fine.

My real confusion starts when I try to tangle the babel code blocks. The
C-c C-v t command produces two separate files just fine, a .tex and .el,
but then if I try to Run Latex on the .tex file just by itself it gives an
error. Here's what the org-mode tangle produces:

\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}

And here's the error log after I try to run it by itself in Emacs:

. . .entering extended mode
 restricted \write18 enabled.
 file:line:error style messages enabled.
 %&-line parsing enabled.
**\input prac2.tex
(./prac2.tex
./prac2.tex:2: Undefined control sequence.
l.2 \usetikzlibrary
                   {trees}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
Another version (from C-c `) produces this error message:

ERROR: Undefined control sequence.

--- TeX said ---
l.2 \usetikzlibrary
                   {trees}
--- HELP ---
TeX encountered an unknown command name. You probably misspelled the
name. If this message occurs when a LaTeX command is being processed,
the command is probably in the wrong place---for example, the error
can be produced by an \item command that's not inside a list-making
environment. The error can also be caused by a missing \documentclass
command.

What am I missing here? I'd like to be able to keep my org stuff separate
from the Latex source, which org-mode seems to do nicely. But then it has
to run properly too. . . .

LB

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

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

* Re: Tangled Latex code gives error
  2015-04-26 23:20 Tangled Latex code gives error Lawrence Bottorff
@ 2015-04-27  1:45 ` Lawrence Bottorff
  2015-04-27  8:28 ` Andreas Leha
  2015-04-27  9:33 ` Eric S Fraga
  2 siblings, 0 replies; 6+ messages in thread
From: Lawrence Bottorff @ 2015-04-27  1:45 UTC (permalink / raw)
  To: emacs-orgmode

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

. . . okay, I realize that a viable Latex document has many preliminary
commands. Here's a "working" version of my tangled code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}

\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{document}

I guess I need to know where to begin to get the "default" org-mode Latex
export functionality for Latex babel tangling.

But then maybe I'm barking up the wrong tree. One of the hardest things
about learning org-mode is finding out what the "best practice" of
something really is.

On Sun, Apr 26, 2015 at 7:20 PM, Lawrence Bottorff <borgauf@gmail.com>
wrote:

> I'm following the Latex howto of org-mode babel. Here's the snippet from
> the howto I've got in a separate .org file (see bottom of howto page):
>
> #+LATEX_HEADER: \usepackage{tikz}
>
> First execute the second code block, to define the convenience macro
> and to set the required new variables in ob-latex.el.  Then export to
> HTML and to pdf to see the tree exported as an SVG image and as
> embedded tikz respectively.
>
> * Tikz test
> Here's a tree, exported to both html and pdf.
>
> #+header: :file (by-backend (html "tree.svg") (t 'nil))
> #+header: :imagemagick
> #+header: :results (by-backend (pdf "latex") (t "raw"))
> #+header: :tangle yes
> #+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
> #+header: :tangle yes
> #+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
>
> This doesn't really produce a .svg of the tree as advertised, but
> exporting to Latex does produce it just fine.
>
> My real confusion starts when I try to tangle the babel code blocks. The
> C-c C-v t command produces two separate files just fine, a .tex and .el,
> but then if I try to Run Latex on the .tex file just by itself it gives an
> error. Here's what the org-mode tangle produces:
>
> \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}
>
> And here's the error log after I try to run it by itself in Emacs:
>
> . . .entering extended mode
>  restricted \write18 enabled.
>  file:line:error style messages enabled.
>  %&-line parsing enabled.
> **\input prac2.tex
> (./prac2.tex
> ./prac2.tex:2: Undefined control sequence.
> l.2 \usetikzlibrary
>                    {trees}
> The control sequence at the end of the top line
> of your error message was never \def'ed. If you have
> misspelled it (e.g., `\hobx'), type `I' and the correct
> spelling (e.g., `I\hbox'). Otherwise just continue,
> and I'll forget about whatever was undefined.
> Another version (from C-c `) produces this error message:
>
> ERROR: Undefined control sequence.
>
> --- TeX said ---
> l.2 \usetikzlibrary
>                    {trees}
> --- HELP ---
> TeX encountered an unknown command name. You probably misspelled the
> name. If this message occurs when a LaTeX command is being processed,
> the command is probably in the wrong place---for example, the error
> can be produced by an \item command that's not inside a list-making
> environment. The error can also be caused by a missing \documentclass
> command.
>
> What am I missing here? I'd like to be able to keep my org stuff separate
> from the Latex source, which org-mode seems to do nicely. But then it has
> to run properly too. . . .
>
> LB
>

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

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

* Re: Tangled Latex code gives error
  2015-04-26 23:20 Tangled Latex code gives error Lawrence Bottorff
  2015-04-27  1:45 ` Lawrence Bottorff
@ 2015-04-27  8:28 ` Andreas Leha
  2015-04-27  9:33 ` Eric S Fraga
  2 siblings, 0 replies; 6+ messages in thread
From: Andreas Leha @ 2015-04-27  8:28 UTC (permalink / raw)
  To: emacs-orgmode

Hi Lawrence,

Lawrence Bottorff <borgauf@gmail.com> writes:
> I'm following the Latex howto of org-mode babel. Here's the snippet
> from the howto I've got in a separate .org file (see bottom of howto
> page):
>
> #+LATEX_HEADER: \usepackage{tikz}
>
> First execute the second code block, to define the convenience macro
> and to set the required new variables in ob-latex.el. Then export to
> HTML and to pdf to see the tree exported as an SVG image and as
> embedded tikz respectively.
>
> * Tikz test
> Here's a tree, exported to both html and pdf.
>
> #+header: :file (by-backend (html "tree.svg") (t 'nil))
> #+header: :imagemagick
> #+header: :results (by-backend (pdf "latex") (t "raw"))
> #+header: :tangle yes
> #+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
> #+header: :tangle yes
> #+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
>
> This doesn't really produce a .svg of the tree as advertised, but
> exporting to Latex does produce it just fine.

Works as advertised for me.  What version of orgmode are you using?
There has been a bug fix in that code recently.

Note, that in that example the :imagemagick flag is superfluous.  It is
necessary, for instance, if you want to be able to get a inline
displayable image in png as well.
Then, the example should be
--8<---------------cut here---------------start------------->8---
#+header: :file (by-backend (html "tree.svg") (t "tree.png"))
#+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
--8<---------------cut here---------------end--------------->8---



>
> My real confusion starts when I try to tangle the babel code blocks.
> The C-c C-v t command produces two separate files just fine, a .tex
> and .el, but then if I try to Run Latex on the .tex file just by
> itself it gives an error. Here's what the org-mode tangle produces:
>

[ ... snip ... ]

Tangling is not meant to produce full LaTeX files.  If you want a full
and compilable LaTeX document, use the export functionality and export
to tex instead of pdf.  Then, you can manually compile the tex file.

Hope that helps,
Andreas

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

* Re: Tangled Latex code gives error
  2015-04-26 23:20 Tangled Latex code gives error Lawrence Bottorff
  2015-04-27  1:45 ` Lawrence Bottorff
  2015-04-27  8:28 ` Andreas Leha
@ 2015-04-27  9:33 ` Eric S Fraga
  2015-04-27 11:58   ` Lawrence Bottorff
  2 siblings, 1 reply; 6+ messages in thread
From: Eric S Fraga @ 2015-04-27  9:33 UTC (permalink / raw)
  To: Lawrence Bottorff; +Cc: emacs-orgmode

On Sunday, 26 Apr 2015 at 19:20, Lawrence Bottorff wrote:
> I'm following the Latex howto of org-mode babel. Here's the snippet from
> the howto I've got in a separate .org file (see bottom of howto page):

[...]

> My real confusion starts when I try to tangle the babel code blocks. The
> C-c C-v t command produces two separate files just fine, a .tex and .el,
> but then if I try to Run Latex on the .tex file just by itself it gives an
> error. Here's what the org-mode tangle produces:

Why do you wish to tangle?  The LaTeX will definitely not work
standalone as it is not complete.  You can export your document to LaTeX
(C-c C-e l l) which is probably what you want?
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org release_8.3beta-1062-gce4e64

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

* Re: Tangled Latex code gives error
  2015-04-27  9:33 ` Eric S Fraga
@ 2015-04-27 11:58   ` Lawrence Bottorff
  2015-04-28  7:33     ` e.fraga
  0 siblings, 1 reply; 6+ messages in thread
From: Lawrence Bottorff @ 2015-04-27 11:58 UTC (permalink / raw)
  To: Lawrence Bottorff, emacs-orgmode

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

I'm attracted to the tangle option because the normal latex export seems to
take everything in my .org file, e.g.,

* Introduction
LaTeX is a document markup language and a document preparation system
for the TeX typesetting program.

#+BEGIN_LaTeX
\begin{eqnarray*}
\hat{f}(x) & \propto & \sum_{\nu} \frac{|F(\nu)H(\nu)|^2}{|N(\nu)|^2}
           \frac{G(\nu)}{H(\nu)} e^{\frac{2 \pi i \nu x}{N}}\\
           & \propto & \sum_{\nu} \frac{|F(\nu)|^2}{|N(\nu)|^2} H(\nu)
H^*(\nu)
           \frac{G(\nu)}{H(\nu)} e^{\frac{2 \pi i \nu x}{N}}\\
           & \propto & \sum_{\nu} H^*(\nu) G(\nu) e^{\frac{2 \pi i \nu
x}{N}}
\end{eqnarray*}
#+END_LaTeX

will result in both the * Introduction blurb as well as the stuff between
the tatex "structural elements" being exported. With latex babel I can
tangle and get only what I want. This is handy if I want to throw around a
lot of chatter and extraneous stuff that ultimately I won't want in my
final document. We might call this "annotations a la orgmode." But, yes,
then I don't get the built-in orgmode latex support that comes with a
regular latex export. Please advise if I'm wrong on this understanding.

On Mon, Apr 27, 2015 at 5:33 AM, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:

> On Sunday, 26 Apr 2015 at 19:20, Lawrence Bottorff wrote:
> > I'm following the Latex howto of org-mode babel. Here's the snippet from
> > the howto I've got in a separate .org file (see bottom of howto page):
>
> [...]
>
> > My real confusion starts when I try to tangle the babel code blocks. The
> > C-c C-v t command produces two separate files just fine, a .tex and .el,
> > but then if I try to Run Latex on the .tex file just by itself it gives
> an
> > error. Here's what the org-mode tangle produces:
>
> Why do you wish to tangle?  The LaTeX will definitely not work
> standalone as it is not complete.  You can export your document to LaTeX
> (C-c C-e l l) which is probably what you want?
> --
> : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org
> release_8.3beta-1062-gce4e64
>

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

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

* Re: Tangled Latex code gives error
  2015-04-27 11:58   ` Lawrence Bottorff
@ 2015-04-28  7:33     ` e.fraga
  0 siblings, 0 replies; 6+ messages in thread
From: e.fraga @ 2015-04-28  7:33 UTC (permalink / raw)
  To: Lawrence Bottorff; +Cc: emacs-orgmode

On Monday, 27 Apr 2015 at 07:58, Lawrence Bottorff wrote:

[...]

> will result in both the * Introduction blurb as well as the stuff
> between
> the tatex "structural elements" being exported. With latex babel I can
> tangle and get only what I want. This is handy if I want to throw
> around a
> lot of chatter and extraneous stuff that ultimately I won't want in my
> final document. We might call this "annotations a la orgmode." But,
> yes,
> then I don't get the built-in orgmode latex support that comes with a
> regular latex export. Please advise if I'm wrong on this
> understanding.

No, your understanding is spot on.  What you can do is have sections in
your org file which do not get exported, using either the :noexport: tag
or by commenting out individual headlines (C-c ;).  However, this is not
quite what you have illustrated in your email.

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.4.1, Org release_8.3beta-790-gb719c1.dirty

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

end of thread, other threads:[~2015-04-28  7:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-26 23:20 Tangled Latex code gives error Lawrence Bottorff
2015-04-27  1:45 ` Lawrence Bottorff
2015-04-27  8:28 ` Andreas Leha
2015-04-27  9:33 ` Eric S Fraga
2015-04-27 11:58   ` Lawrence Bottorff
2015-04-28  7:33     ` e.fraga

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).