emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org mode with babel source: execute all source blocks, don't export them to latex
@ 2020-10-13  6:29 Uwe Brauer
  2020-10-13  7:04 ` Diego Zamboni
  0 siblings, 1 reply; 12+ messages in thread
From: Uwe Brauer @ 2020-10-13  6:29 UTC (permalink / raw)
  To: emacs-orgmode



Hi 

I have a org file with has a lot source blocks of the form 

#+begin_src matlab  :results output raw :exports code  :eval never-export
close all
N = 3; % number of chebyshev nodes
n = 1; % polytropic index
iters = 1; % iterations
j=[0 1 2 3];
z=cos((pi*j)/3);
y=1-(0.5*(z+1)).^2;
a=n*(8);
a2=eye(3+1)*a;
disp('\begin{align*}')
disp('A_{1,k-1}&=')
disp('\begin{pmatrix}')
fprintf('%g &%g &%g &%g\\\\\n',a2')
disp('\end{pmatrix}=OK\\')
disp('\end{align*}')
#+end_src

#+RESULTS:
\begin{align*}
A_{1,k-1}&=
\begin{pmatrix}
8 &0 &0 &0\\
0 &8 &0 &0\\
0 &0 &8 &0\\
0 &0 &0 &8\\
\end{pmatrix}=OK\\
\end{align*}

Two questions. 

    1. Is there any equivalent to org-update-all-dblocks for the source blocks?

    2. I want to export the org file to latex, in the current setting
       the source blocks are also exported. I tried
       #+begin_src matlab  :results output raw   :eval never-export
       but it did not help. 

Thanks 

Uwe Brauer 



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

* Re: org mode with babel source: execute all source blocks, don't export them to latex
  2020-10-13  6:29 org mode with babel source: execute all source blocks, don't export them to latex Uwe Brauer
@ 2020-10-13  7:04 ` Diego Zamboni
  2020-10-13  7:26   ` [matlab src is always exported to latex!!] (was: org mode with babel source: execute all source blocks, don't export them to latex) Uwe Brauer
  0 siblings, 1 reply; 12+ messages in thread
From: Diego Zamboni @ 2020-10-13  7:04 UTC (permalink / raw)
  To: Org-mode

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

Hi Uwe,

    1. Is there any equivalent to org-update-all-dblocks for the source
> blocks?
>

I think you want org-babel-execute-buffer:


Documentation
Call org-babel-execute-src-block on every source block in

the current buffer.

     2. I want to export the org file to latex, in the current setting
>        the source blocks are also exported. I tried
>        #+begin_src matlab  :results output raw   :eval never-export
>        but it did not help.
>

Normally, =:results output= should be enough, but there might be some
peculiarities with matlab blocks that change this behavior.

--Diego

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

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

* [matlab src is always exported to latex!!] (was: org mode with babel source: execute all source blocks, don't export them to latex)
  2020-10-13  7:04 ` Diego Zamboni
@ 2020-10-13  7:26   ` Uwe Brauer
  2020-10-13  8:31     ` [solution of sorts] (was: [matlab src is always exported to latex!!]) Uwe Brauer
                       ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Uwe Brauer @ 2020-10-13  7:26 UTC (permalink / raw)
  To: emacs-orgmode

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


Hi Diego

Thanks for the quick answer
> Hi Uwe,
>     1. Is there any equivalent to org-update-all-dblocks for the source

> I think you want org-babel-execute-buffer:

Right, thanks!!!


> Documentation
> Call org-babel-execute-src-block on every source block in

> the current buffer.

>      2. I want to export the org file to latex, in the current setting

> Normally, =:results output= should be enough, but there might be some
> peculiarities with matlab blocks that change this behavior.


That did not work: I tried
#+begin_src matlab  :results output 

But when I exported the org file to latex, the matlab code was also
exported. Strange 

Anybody has an idea?

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* [solution of sorts] (was: [matlab src is always exported to latex!!])
  2020-10-13  7:26   ` [matlab src is always exported to latex!!] (was: org mode with babel source: execute all source blocks, don't export them to latex) Uwe Brauer
@ 2020-10-13  8:31     ` Uwe Brauer
  2020-10-13  8:31     ` [matlab src is always exported to latex!!] Eric S Fraga
  2020-10-13  8:44     ` [matlab src is always exported to latex!!] (was: org mode with babel source: execute all source blocks, don't export them to latex) Dr. Arne Babenhauserheide
  2 siblings, 0 replies; 12+ messages in thread
From: Uwe Brauer @ 2020-10-13  8:31 UTC (permalink / raw)
  To: emacs-orgmode

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





> That did not work: I tried
> #+begin_src matlab  :results output 

> But when I exported the org file to latex, the matlab code was also
> exported. Strange 

The only solution I am aware is to have something like this 



(defun my-latex-filter-src-blocks (text backend info)
  "Remove source blocks from latex export."
  (when (org-export-derived-backend-p backend 'latex)
    "%% [removed source block]\n"))

(defun my-html-filter-src-blocks (text backend info)
  "Remove source blocks from latex export."
  (when (org-export-derived-backend-p backend 'html)
    "%% [removed source block]\n"))

(add-to-list 'org-export-filter-src-block-functions
         'my-latex-filter-src-blocks)

(add-to-list 'org-export-filter-src-block-functions
         'my-html-filter-src-blocks)



[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* Re: [matlab src is always exported to latex!!]
  2020-10-13  7:26   ` [matlab src is always exported to latex!!] (was: org mode with babel source: execute all source blocks, don't export them to latex) Uwe Brauer
  2020-10-13  8:31     ` [solution of sorts] (was: [matlab src is always exported to latex!!]) Uwe Brauer
@ 2020-10-13  8:31     ` Eric S Fraga
  2020-10-13 11:31       ` Uwe Brauer
  2020-10-13  8:44     ` [matlab src is always exported to latex!!] (was: org mode with babel source: execute all source blocks, don't export them to latex) Dr. Arne Babenhauserheide
  2 siblings, 1 reply; 12+ messages in thread
From: Eric S Fraga @ 2020-10-13  8:31 UTC (permalink / raw)
  To: emacs-orgmode

On Tuesday, 13 Oct 2020 at 09:26, Uwe Brauer wrote:
> That did not work: I tried
> #+begin_src matlab  :results output 
> But when I exported the org file to latex, the matlab code was also
> exported. Strange 

If you want the output only, you also need to add ":exports results".

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4-57-g8402c4


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

* Re: [matlab src is always exported to latex!!] (was: org mode with babel source: execute all source blocks, don't export them to latex)
  2020-10-13  7:26   ` [matlab src is always exported to latex!!] (was: org mode with babel source: execute all source blocks, don't export them to latex) Uwe Brauer
  2020-10-13  8:31     ` [solution of sorts] (was: [matlab src is always exported to latex!!]) Uwe Brauer
  2020-10-13  8:31     ` [matlab src is always exported to latex!!] Eric S Fraga
@ 2020-10-13  8:44     ` Dr. Arne Babenhauserheide
  2020-10-13 11:34       ` [matlab src is always exported to latex!!] Uwe Brauer
  2 siblings, 1 reply; 12+ messages in thread
From: Dr. Arne Babenhauserheide @ 2020-10-13  8:44 UTC (permalink / raw)
  To: Uwe Brauer; +Cc: emacs-orgmode

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


Uwe Brauer <oub@mat.ucm.es> writes:

> That did not work: I tried
> #+begin_src matlab  :results output 
>
> But when I exported the org file to latex, the matlab code was also
> exported. Strange 

Do you use :exports results?

:results output switches to show what is printed to stdout

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]

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

* Re: [matlab src is always exported to latex!!]
  2020-10-13  8:31     ` [matlab src is always exported to latex!!] Eric S Fraga
@ 2020-10-13 11:31       ` Uwe Brauer
  0 siblings, 0 replies; 12+ messages in thread
From: Uwe Brauer @ 2020-10-13 11:31 UTC (permalink / raw)
  To: emacs-orgmode

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

>>> "ESF" == Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> On Tuesday, 13 Oct 2020 at 09:26, Uwe Brauer wrote:
>> That did not work: I tried
>> #+begin_src matlab  :results output 
>> But when I exported the org file to latex, the matlab code was also
>> exported. Strange 

> If you want the output only, you also need to add ":exports results".
Hm not really

#+begin_src matlab :exports results
close all
N = 3; % number of chebyshev nodes
n = 1; % polytropic index
iters = 1; % iterations
j=[0 1 2 3];
z=cos((pi*j)/3);
y=1-(0.5*(z+1)).^2;
a=n*(8);
a2=eye(3+1)*a;
disp('\begin{align*}')
disp('A_{1,k-1}&=')
disp('\begin{pmatrix}')
fprintf('%g &%g &%g &%g\\\\\n',a2')
disp('\end{pmatrix}=OK\\')
disp('\end{align*}')
#+end_src
when I export this to latex I obtain 

\begin{verbatim}
\begin{align*}
A_{1,k-1}&=
\begin{pmatrix}
8 &0 &0 &0\\
0 &8 &0 &0\\
0 &0 &8 &0\\
0 &0 &0 &8\\
\end{pmatrix}=OK\\
\end{align*}
\end{verbatim}

Which is not what I want. I don't want a verbatim environment

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* Re: [matlab src is always exported to latex!!]
  2020-10-13  8:44     ` [matlab src is always exported to latex!!] (was: org mode with babel source: execute all source blocks, don't export them to latex) Dr. Arne Babenhauserheide
@ 2020-10-13 11:34       ` Uwe Brauer
  2020-10-13 12:11         ` Diego Zamboni
  0 siblings, 1 reply; 12+ messages in thread
From: Uwe Brauer @ 2020-10-13 11:34 UTC (permalink / raw)
  To: emacs-orgmode

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

>>> "AB" == Arne Babenhauserheide <arne_bab@web.de> writes:

> Uwe Brauer <oub@mat.ucm.es> writes:

>> That did not work: I tried
>> #+begin_src matlab  :results output 
>> 
>> But when I exported the org file to latex, the matlab code was also
>> exported. Strange 

> Do you use :exports results?

> :results output switches to show what is printed to stdout

See my answer to Eric

It does not do want I want
#+begin_src matlab :exports results
close all
N = 3; % number of chebyshev nodes
n = 1; % polytropic index
iters = 1; % iterations
j=[0 1 2 3];
z=cos((pi*j)/3);
y=1-(0.5*(z+1)).^2;
a=n*(8);
a2=eye(3+1)*a;
disp('\begin{align*}')
disp('A_{1,k-1}&=')
disp('\begin{pmatrix}')
fprintf('%g &%g &%g &%g\\\\\n',a2')
disp('\end{pmatrix}=OK\\')
disp('\end{align*}')
#+end_src

Leads to 

\begin{verbatim}
\begin{align*}
A_{1,k-1}&=
\begin{pmatrix}
8 &0 &0 &0\\
0 &8 &0 &0\\
0 &0 &8 &0\\
0 &0 &0 &8\\
\end{pmatrix}=OK\\
\end{align*}
\end{verbatim}

So at the moment the only solution I can think of is to use the code I
posted 

(defun my-latex-filter-src-blocks (text backend info)
  "Remove source blocks from latex export."
  (when (org-export-derived-backend-p backend 'latex)
    "%% [removed source block]\n"))

(add-to-list 'org-export-filter-src-block-functions
         'my-latex-filter-src-blocks)

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* Re: [matlab src is always exported to latex!!]
  2020-10-13 11:34       ` [matlab src is always exported to latex!!] Uwe Brauer
@ 2020-10-13 12:11         ` Diego Zamboni
  2020-10-13 12:56           ` Uwe Brauer
  0 siblings, 1 reply; 12+ messages in thread
From: Diego Zamboni @ 2020-10-13 12:11 UTC (permalink / raw)
  To: Org-mode

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

Uwe,

In my testing (using octave since I don't have matlab, but I hope it's
similar), using = :exports none :results output raw= seems to produce the
desired output:

#+begin_src octave :exports results :results output raw
close all
N = 3; % number of chebyshev nodes
n = 1; % polytropic index
iters = 1; % iterations
j=[0 1 2 3];
z=cos((pi*j)/3);
y=1-(0.5*(z+1)).^2;
a=n*(8);
a2=eye(3+1)*a;
disp('\begin{align*}')
disp('A_{1,k-1}&=')
disp('\begin{pmatrix}')
fprintf('%g &%g &%g &%g\\\\\n',a2')
disp('\end{pmatrix}=OK\\')
disp('\end{align*}')
#+end_src

#+RESULTS:
\begin{align*}
A_{1,k-1}&=
\begin{pmatrix}
8 &0 &0 &0\\
0 &8 &0 &0\\
0 &0 &8 &0\\
0 &0 &0 &8\\
\end{pmatrix}=OK\\
\end{align*}

Which renders the matrix correctly. I first tried with =:exports results=,
but that for some reason results in the results being included twice in the
LaTeX output. I'm not sure why.

Hope this helps,
--Diego


On Tue, Oct 13, 2020 at 1:36 PM Uwe Brauer <oub@mat.ucm.es> wrote:

> >>> "AB" == Arne Babenhauserheide <arne_bab@web.de> writes:
>
> > Uwe Brauer <oub@mat.ucm.es> writes:
>
> >> That did not work: I tried
> >> #+begin_src matlab  :results output
> >>
> >> But when I exported the org file to latex, the matlab code was also
> >> exported. Strange
>
> > Do you use :exports results?
>
> > :results output switches to show what is printed to stdout
>
> See my answer to Eric
>
> It does not do want I want
> #+begin_src matlab :exports results
> close all
> N = 3; % number of chebyshev nodes
> n = 1; % polytropic index
> iters = 1; % iterations
> j=[0 1 2 3];
> z=cos((pi*j)/3);
> y=1-(0.5*(z+1)).^2;
> a=n*(8);
> a2=eye(3+1)*a;
> disp('\begin{align*}')
> disp('A_{1,k-1}&=')
> disp('\begin{pmatrix}')
> fprintf('%g &%g &%g &%g\\\\\n',a2')
> disp('\end{pmatrix}=OK\\')
> disp('\end{align*}')
> #+end_src
>
> Leads to
>
> \begin{verbatim}
> \begin{align*}
> A_{1,k-1}&=
> \begin{pmatrix}
> 8 &0 &0 &0\\
> 0 &8 &0 &0\\
> 0 &0 &8 &0\\
> 0 &0 &0 &8\\
> \end{pmatrix}=OK\\
> \end{align*}
> \end{verbatim}
>
> So at the moment the only solution I can think of is to use the code I
> posted
>
> (defun my-latex-filter-src-blocks (text backend info)
>   "Remove source blocks from latex export."
>   (when (org-export-derived-backend-p backend 'latex)
>     "%% [removed source block]\n"))
>
> (add-to-list 'org-export-filter-src-block-functions
>          'my-latex-filter-src-blocks)
>

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

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

* Re: [matlab src is always exported to latex!!]
  2020-10-13 12:11         ` Diego Zamboni
@ 2020-10-13 12:56           ` Uwe Brauer
  2020-10-13 12:59             ` Eric S Fraga
  0 siblings, 1 reply; 12+ messages in thread
From: Uwe Brauer @ 2020-10-13 12:56 UTC (permalink / raw)
  To: emacs-orgmode

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

>>> "DZ" == Diego Zamboni <diego@zzamboni.org> writes:

Hi Diego


> Uwe,
> In my testing (using octave since I don't have matlab, but I hope it's
> similar), using = :exports none :results output raw= seems to produce the
> desired output:

> #+begin_src octave :exports results :results output raw

That's it. That solves it, thanks so my function is not necessary. Good
to know

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* Re: [matlab src is always exported to latex!!]
  2020-10-13 12:56           ` Uwe Brauer
@ 2020-10-13 12:59             ` Eric S Fraga
  2020-10-13 17:21               ` Uwe Brauer
  0 siblings, 1 reply; 12+ messages in thread
From: Eric S Fraga @ 2020-10-13 12:59 UTC (permalink / raw)
  To: emacs-orgmode

On Tuesday, 13 Oct 2020 at 14:56, Uwe Brauer wrote:
>>>> "DZ" == Diego Zamboni <diego@zzamboni.org> writes:
>> #+begin_src octave :exports results :results output raw
>
> That's it. That solves it, thanks so my function is not necessary. Good
> to know

The problem with =raw= is that you may find you have to manually delete
the previous results if you change and re-execute the src block.  Use
=latex= instead.

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4-57-g8402c4


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

* Re: [matlab src is always exported to latex!!]
  2020-10-13 12:59             ` Eric S Fraga
@ 2020-10-13 17:21               ` Uwe Brauer
  0 siblings, 0 replies; 12+ messages in thread
From: Uwe Brauer @ 2020-10-13 17:21 UTC (permalink / raw)
  To: emacs-orgmode

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

>>> "ESF" == Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> On Tuesday, 13 Oct 2020 at 14:56, Uwe Brauer wrote:
>>>>> "DZ" == Diego Zamboni <diego@zzamboni.org> writes:
>>> #+begin_src octave :exports results :results output raw
>> 
>> That's it. That solves it, thanks so my function is not necessary. Good
>> to know

> The problem with =raw= is that you may find you have to manually delete
> the previous results if you change and re-execute the src block.  Use
> =latex= instead.

Ok, thanks

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

end of thread, other threads:[~2020-10-13 17:22 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-13  6:29 org mode with babel source: execute all source blocks, don't export them to latex Uwe Brauer
2020-10-13  7:04 ` Diego Zamboni
2020-10-13  7:26   ` [matlab src is always exported to latex!!] (was: org mode with babel source: execute all source blocks, don't export them to latex) Uwe Brauer
2020-10-13  8:31     ` [solution of sorts] (was: [matlab src is always exported to latex!!]) Uwe Brauer
2020-10-13  8:31     ` [matlab src is always exported to latex!!] Eric S Fraga
2020-10-13 11:31       ` Uwe Brauer
2020-10-13  8:44     ` [matlab src is always exported to latex!!] (was: org mode with babel source: execute all source blocks, don't export them to latex) Dr. Arne Babenhauserheide
2020-10-13 11:34       ` [matlab src is always exported to latex!!] Uwe Brauer
2020-10-13 12:11         ` Diego Zamboni
2020-10-13 12:56           ` Uwe Brauer
2020-10-13 12:59             ` Eric S Fraga
2020-10-13 17:21               ` Uwe Brauer

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