emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] configuring LaTeX exports verbatim environment for exported code and results
@ 2010-08-31 13:08 Douglas Bates
  2010-08-31 13:28 ` Douglas Bates
  0 siblings, 1 reply; 3+ messages in thread
From: Douglas Bates @ 2010-08-31 13:08 UTC (permalink / raw)
  To: emacs-orgmode

I have been unable to find in the documentation whether the verbatim
environment created by LaTeX exports of source code blocks can be
configured.

Exporting to LaTeX a section like

--8<---------------cut here---------------start------------->8---
#+LaTeX_CLASS: beamer
#+LaTeX_CLASS_OPTIONS: [presentation]
#+BEAMER_FRAME_LEVEL: 1
#+BABEL: :session :exports both :results output :tangle yes

* Fitting a simple linear regression
#+begin_src R :exports results
options(show.signif.stars=FALSE)
#+end_src
#+begin_src R
summary(fm1 <- lm(optden ~ carb, Formaldehyde))
#+end_src
A final line.
--8<---------------cut here---------------end--------------->8---

produces the LaTeX section

--8<---------------cut here---------------start------------->8---
\begin{frame}[fragile]
\frametitle{Fitting a simple linear regression}
\label{sec-1}

\begin{verbatim}
summary(fm1 <- lm(optden ~ carb, Formaldehyde))
\end{verbatim}



\begin{verbatim}

Call:
lm(formula = optden ~ carb, data = Formaldehyde)

Residuals:
        1         2         3         4         5         6
-0.006714  0.001029  0.002771  0.007143  0.007514 -0.011743

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.005086   0.007834   0.649    0.552
carb        0.876286   0.013535  64.744 3.41e-07

Residual standard error: 0.008649 on 4 degrees of freedom
Multiple R-squared: 0.999,      Adjusted R-squared: 0.9988
F-statistic:  4192 on 1 and 4 DF,  p-value: 3.409e-07
\end{verbatim}

A final line.
\end{frame}
--8<---------------cut here---------------end--------------->8---

Because both the source and the results are presented in verbatim, I
don't have much control over the appearance of the code on the slide.
If I could, for example, configure the names of the exported
environment for the source code and for the results separately, I
could use LaTeX's fancyvrb.sty to adjust font sizes, colors, boxes,
etc.

Also, the blank lines before and after the verbatim environment are
problematic.  In plain text it makes sense to delimit code chunks with
blank lines but in LaTeX a blank line starts a new paragraph and you
don't always want that.

As this is my first posting please let me know if I have inadvertently
violated conventions of the list.


Also, the exports append blank lines

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

* Re: [babel] configuring LaTeX exports verbatim environment for exported code and results
  2010-08-31 13:08 [babel] configuring LaTeX exports verbatim environment for exported code and results Douglas Bates
@ 2010-08-31 13:28 ` Douglas Bates
  2010-08-31 14:40   ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: Douglas Bates @ 2010-08-31 13:28 UTC (permalink / raw)
  To: emacs-orgmode

On Tue, Aug 31, 2010 at 8:08 AM, Douglas Bates <bates@stat.wisc.edu> wrote:
> I have been unable to find in the documentation whether the verbatim
> environment created by LaTeX exports of source code blocks can be
> configured.
>
> Exporting to LaTeX a section like
>
> --8<---------------cut here---------------start------------->8---
> #+LaTeX_CLASS: beamer
> #+LaTeX_CLASS_OPTIONS: [presentation]
> #+BEAMER_FRAME_LEVEL: 1
> #+BABEL: :session :exports both :results output :tangle yes
>
> * Fitting a simple linear regression
> #+begin_src R :exports results
> options(show.signif.stars=FALSE)
> #+end_src
> #+begin_src R
> summary(fm1 <- lm(optden ~ carb, Formaldehyde))
> #+end_src
> A final line.
> --8<---------------cut here---------------end--------------->8---
>
> produces the LaTeX section
>
> --8<---------------cut here---------------start------------->8---
> \begin{frame}[fragile]
> \frametitle{Fitting a simple linear regression}
> \label{sec-1}
>
> \begin{verbatim}
> summary(fm1 <- lm(optden ~ carb, Formaldehyde))
> \end{verbatim}
>
>
>
> \begin{verbatim}
>
> Call:
> lm(formula = optden ~ carb, data = Formaldehyde)
>
> Residuals:
>        1         2         3         4         5         6
> -0.006714  0.001029  0.002771  0.007143  0.007514 -0.011743
>
> Coefficients:
>            Estimate Std. Error t value Pr(>|t|)
> (Intercept) 0.005086   0.007834   0.649    0.552
> carb        0.876286   0.013535  64.744 3.41e-07
>
> Residual standard error: 0.008649 on 4 degrees of freedom
> Multiple R-squared: 0.999,      Adjusted R-squared: 0.9988
> F-statistic:  4192 on 1 and 4 DF,  p-value: 3.409e-07
> \end{verbatim}
>
> A final line.
> \end{frame}
> --8<---------------cut here---------------end--------------->8---
>
> Because both the source and the results are presented in verbatim, I
> don't have much control over the appearance of the code on the slide.
> If I could, for example, configure the names of the exported
> environment for the source code and for the results separately, I
> could use LaTeX's fancyvrb.sty to adjust font sizes, colors, boxes,
> etc.

I just realized that if the code and results are wrapped in other than
the verbatim environment the org-beamer-fragile-re variable will need
to be customized.  (By the way, automatically detecting the need for
the fragile option is a great idea.)

> Also, the blank lines before and after the verbatim environment are
> problematic.  In plain text it makes sense to delimit code chunks with
> blank lines but in LaTeX a blank line starts a new paragraph and you
> don't always want that.
>
> As this is my first posting please let me know if I have inadvertently
> violated conventions of the list.

Well, other than my cut-and-paste glich below :-/
>
> Also, the exports append blank lines
>

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

* Re: Re: [babel] configuring LaTeX exports verbatim environment for exported code and results
  2010-08-31 13:28 ` Douglas Bates
@ 2010-08-31 14:40   ` Eric Schulte
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2010-08-31 14:40 UTC (permalink / raw)
  To: Douglas Bates; +Cc: emacs-orgmode

Hi Douglas,

Douglas Bates <bates@stat.wisc.edu> writes:

> On Tue, Aug 31, 2010 at 8:08 AM, Douglas Bates <bates@stat.wisc.edu> wrote:
>> I have been unable to find in the documentation whether the verbatim
>> environment created by LaTeX exports of source code blocks can be
>> configured.
>>

It is possible to export code using the LaTeX listings package.  See
`org-export-latex-listings'
,----
| org-export-latex-listings is a variable defined in `org-latex.el'.
| Its value is t
| 
| Documentation:
| Non-nil means export source code using the listings package.
| This package will fontify source code, possibly even with color.
| If you want to use this, you also need to make LaTeX use the
| listings package, and if you want to have color, the color
| package.  Just add these to `org-export-latex-packages-alist',
| for example using customize, or with something like
| 
|   (require 'org-latex)
|   (add-to-list 'org-export-latex-packages-alist '("" "listings"))
|   (add-to-list 'org-export-latex-packages-alist '("" "color"))
| 
| You can customize this variable.
| 
| [back]
`----

>>
>> Exporting to LaTeX a section like
[...]
>>
>> Because both the source and the results are presented in verbatim, I
>> don't have much control over the appearance of the code on the slide.
>> If I could, for example, configure the names of the exported
>> environment for the source code and for the results separately, I
>> could use LaTeX's fancyvrb.sty to adjust font sizes, colors, boxes,
>> etc.
>

Listings gives good control over the look of code on a slide, I
generally use the following as my jumping off point for listings style
in Beamer presentations
--8<---------------cut here---------------start------------->8---
#+begin_LaTeX
  \definecolor{dkgreen}{rgb}{0,0.5,0}
  \definecolor{dkred}{rgb}{0.5,0,0}
  \definecolor{gray}{rgb}{0.5,0.5,0.5}
  \lstset{basicstyle=\ttfamily\bfseries\footnotesize,
    morekeywords={virtualinvoke},
    keywordstyle=\color{blue},
    ndkeywordstyle=\color{red},
    commentstyle=\color{dkred},
    stringstyle=\color{dkgreen},
    numbers=left,
    numberstyle=\ttfamily\tiny\color{gray},
    stepnumber=1,
    numbersep=10pt,
    backgroundcolor=\color{white},
    tabsize=4,
    showspaces=false,
    showstringspaces=false,
    xleftmargin=.23in
  }
#+end_LaTeX
--8<---------------cut here---------------end--------------->8---

>
> I just realized that if the code and results are wrapped in other than
> the verbatim environment the org-beamer-fragile-re variable will need
> to be customized.

No, I believe this works with listings blocks out of the box.

> (By the way, automatically detecting the need for the fragile option
> is a great idea.)
>
>> Also, the blank lines before and after the verbatim environment are
>> problematic.  In plain text it makes sense to delimit code chunks with
>> blank lines but in LaTeX a blank line starts a new paragraph and you
>> don't always want that.
>>

You can manually place the #+results line anywhere in the org-mode file
(even immediately after the code block), however it seems the blank
lines still appear in the exported tex file.  This appears to be an
issue with the LaTeX exporter in general rather than Code blocks in
particular.

>>
>> As this is my first posting please let me know if I have
>>inadvertently violated conventions of the list.
>

Looks good to me.

Cheers -- Eric

>
> Well, other than my cut-and-paste glich below :-/
>>
>> Also, the exports append blank lines
>>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

end of thread, other threads:[~2010-08-31 14:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-31 13:08 [babel] configuring LaTeX exports verbatim environment for exported code and results Douglas Bates
2010-08-31 13:28 ` Douglas Bates
2010-08-31 14:40   ` Eric Schulte

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