emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Treat custom environment as verbatim on export
@ 2015-05-23  3:09 Jacob Gerlach
  2015-05-23  9:48 ` Rasmus
  2015-05-23 16:32 ` Charles C. Berry
  0 siblings, 2 replies; 7+ messages in thread
From: Jacob Gerlach @ 2015-05-23  3:09 UTC (permalink / raw)
  To: Org-mode

Hello,

I want to use a one of several custom environments for some babel
results using, for example, ":wrap myverbatim" as a header argument.
(Since I have several possible environments, I think I need to use
:wrap rather than, say, replacing "verbatim" using an export filter).

However, since this block isn't recognized as an actual verbatim
environment, markup gets processed in undesirable ways.

For example:

-------------
#+BEGIN_SRC sh :exports results :wrap myverbatim
echo "Hello_world"
#+END_SRC

#+RESULTS:
#+BEGIN_myverbatim
Hello_world
#+END_myverbatim
-------------
exports to
-------------
\begin{myverbatim}
Hello\(_{\text{world}}\)
\end{myverbatim}
-------------
instead of
-------------
\begin{myverbatim}
Hello_world
\end{myverbatim}
-------------

A couple questions:

- Is there any way I've missed to specify verbatim export as an option
for an arbitrary block/environment?

- If not, I think that I need a derived exporter to achieve this, but
the `contents' of a special-block have already had markup transcoded
by the time the derived backend function sees them. What functions
would my derived backend need to replace to allow applying verbatim
formatting to block types of my choosing?

Thanks for any tips,
Jake

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

* Re: Treat custom environment as verbatim on export
  2015-05-23  3:09 Treat custom environment as verbatim on export Jacob Gerlach
@ 2015-05-23  9:48 ` Rasmus
  2015-05-24 15:29   ` Nicolas Goaziou
  2015-05-23 16:32 ` Charles C. Berry
  1 sibling, 1 reply; 7+ messages in thread
From: Rasmus @ 2015-05-23  9:48 UTC (permalink / raw)
  To: emacs-orgmode

Hi Jacob,

Jacob Gerlach <jacobgerlach@gmail.com> writes:

> I want to use a one of several custom environments for some babel
> results using, for example, ":wrap myverbatim" as a header argument.
> (Since I have several possible environments, I think I need to use
> :wrap rather than, say, replacing "verbatim" using an export filter).
>
> However, since this block isn't recognized as an actual verbatim
> environment, markup gets processed in undesirable ways.

I remember that you already set custom export for your source blocks.  So
how about just mirroring that?  E.g.

#+BEGIN_SRC sh :exports results :results value code
echo "Hello_world"
#+END_SRC

#+RESULTS:
#+BEGIN_SRC sh
Hello_world
#+END_SRC

BTW: All headers are documented here:

     http://orgmode.org/manual/Specific-header-arguments.html

> - Is there any way I've missed to specify verbatim export as an option
> for an arbitrary block/environment?

The thing is :wrap doesn't play nicely with :results, but I cannot specify
how I expect them to behave.

> - If not, I think that I need a derived exporter to achieve this, but
> the `contents' of a special-block have already had markup transcoded
> by the time the derived backend function sees them. What functions
> would my derived backend need to replace to allow applying verbatim
> formatting to block types of my choosing?

It's a special block, so e.g. org-latex-special-block.  But contents is
already transcoded by the time in arrives to e.g. org-latex-special-block.
To the extend this should be fixed, one way would be to allow a raw option
to special blocks (also needed for e.g. #+{begin,end}_equation) and have
babel insert it as needed.  I don't know how easy this is.

Rasmus

-- 
I feel emotional landscapes they puzzle me

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

* Re: Treat custom environment as verbatim on export
  2015-05-23  3:09 Treat custom environment as verbatim on export Jacob Gerlach
  2015-05-23  9:48 ` Rasmus
@ 2015-05-23 16:32 ` Charles C. Berry
  1 sibling, 0 replies; 7+ messages in thread
From: Charles C. Berry @ 2015-05-23 16:32 UTC (permalink / raw)
  To: Jacob Gerlach; +Cc: Org-mode

On Fri, 22 May 2015, Jacob Gerlach wrote:

> Hello,
>
> I want to use a one of several custom environments for some babel
> results using, for example, ":wrap myverbatim" as a header argument.
> (Since I have several possible environments, I think I need to use
> :wrap rather than, say, replacing "verbatim" using an export filter).
>
> However, since this block isn't recognized as an actual verbatim
> environment, markup gets processed in undesirable ways.
>
> For example:
>
> -------------
> #+BEGIN_SRC sh :exports results :wrap myverbatim
> echo "Hello_world"
> #+END_SRC
>
> #+RESULTS:
> #+BEGIN_myverbatim
> Hello_world
> #+END_myverbatim
> -------------
> exports to
> -------------
> \begin{myverbatim}
> Hello\(_{\text{world}}\)
> \end{myverbatim}
> -------------
> instead of
> -------------
> \begin{myverbatim}
> Hello_world
> \end{myverbatim}
> -------------
>
> A couple questions:
>
> - Is there any way I've missed to specify verbatim export as an option
> for an arbitrary block/environment?
>


You can use arbritrary latex environments inside a latex block with these 
header arguments:

:  :results raw :wrap latex :post postenv("env-name-goes-here")

If you define a wrapper for the results like this:

#+NAME: postenv
#+BEGIN_SRC emacs-lisp :var env="myverb"  :exports none
(format "\\begin{%s}\n%s\\end{%s}" env *this* env)
#+END_SRC

Then calling

#+header: :results raw :wrap latex :post postenv("myverbatim")
#+BEGIN_SRC sh :exports results
echo "Hello_world"
#+END_SRC

gives:

,----
| \begin{myverbatim}
| Hello_world
| \end{myverbatim}
`----

under latex export.

The `:results raw' is needed particularly for multiline results.

See the manual for each of those header args for more info.

You can also do this using :prologue and :epilogue, but I think :post is a 
bit neater.


HTH,

Chuck

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

* Re: Treat custom environment as verbatim on export
  2015-05-23  9:48 ` Rasmus
@ 2015-05-24 15:29   ` Nicolas Goaziou
  2015-05-24 17:29     ` Rasmus
  2015-05-24 19:43     ` Charles C. Berry
  0 siblings, 2 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2015-05-24 15:29 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

> It's a special block, so e.g. org-latex-special-block.  But contents is
> already transcoded by the time in arrives to e.g. org-latex-special-block.
> To the extend this should be fixed, one way would be to allow a raw option
> to special blocks (also needed for e.g. #+{begin,end}_equation) and have
> babel insert it as needed.  I don't know how easy this is.

I don't think a ":raw" option for special blocks is worth implementing.

There are two types or "raw" contents: "protected raw" (i.e., verbatim
contents) and "export-specific raw" (i.e., target language code). For
the former, we already have example blocks (or fixed-width areas) and
for the latter, export blocks.

A third category exists, "multi-language raw", in which, I think, only
the most trivial cases (those you never really need in practice) would
fit.

The OP wants special "protected raw" for LaTeX back-end. We could
provide a special attribute for this, e.g.,

  #+ATTR_LATEX: :environment "my-verbatim"
  #+BEGIN_EXAMPLE
  ... stuff...
  #+END_EXAMPLE

But this is really only a shortcut for

  #+BEGIN_my-verbatim
  #+BEGIN_LATEX
  stuff
  #+END_LATEX
  #+END_my-verbatim

WDYT?

Regards,

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

* Re: Treat custom environment as verbatim on export
  2015-05-24 15:29   ` Nicolas Goaziou
@ 2015-05-24 17:29     ` Rasmus
  2015-05-24 19:43     ` Charles C. Berry
  1 sibling, 0 replies; 7+ messages in thread
From: Rasmus @ 2015-05-24 17:29 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Rasmus <rasmus@gmx.us> writes:
>
>> It's a special block, so e.g. org-latex-special-block.  But contents is
>> already transcoded by the time in arrives to e.g. org-latex-special-block.
>> To the extend this should be fixed, one way would be to allow a raw option
>> to special blocks (also needed for e.g. #+{begin,end}_equation) and have
>> babel insert it as needed.  I don't know how easy this is.
>
> I don't think a ":raw" option for special blocks is worth implementing.
>
> There are two types or "raw" contents: "protected raw" (i.e., verbatim
> contents) and "export-specific raw" (i.e., target language code). For
> the former, we already have example blocks (or fixed-width areas) and
> for the latter, export blocks.
>
> A third category exists, "multi-language raw", in which, I think, only
> the most trivial cases (those you never really need in practice) would
> fit.
>
> The OP wants special "protected raw" for LaTeX back-end. We could
> provide a special attribute for this, e.g.,
>
>   #+ATTR_LATEX: :environment "my-verbatim"
>
>   #+BEGIN_EXAMPLE
>   ... stuff...
>   #+END_EXAMPLE
>
>
> But this is really only a shortcut for
>
>   #+BEGIN_my-verbatim
>   #+BEGIN_LATEX
>   stuff
>   #+END_LATEX
>   #+END_my-verbatim
>
> WDYT?

If the end goal is 

   #+BEGIN_my-verbatim
   #+BEGIN_LATEX
   stuff
   #+END_LATEX
   #+END_my-verbatim

Then I think it should be producible with babel via

   #+begin_src Emacs-lisp :wrap my-verbatim :results latex
   "stuff"
   #+end_src

However,

   #+ATTR_LATEX: :environment "my-verbatim"
   #+BEGIN_EXAMPLE
   ... stuff...
   #+END_EXAMPLE

Is more general since it also produce sensible output in other backends.

Thus, I think passing attr arguments to example blocks may be
preferable...  Though *if* you are only going for latex export, :wrap
my-verbatim :results latex seems more convenient to me.

Rasmus


-- 
This message is brought to you by the department of redundant departments

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

* Re: Treat custom environment as verbatim on export
  2015-05-24 15:29   ` Nicolas Goaziou
  2015-05-24 17:29     ` Rasmus
@ 2015-05-24 19:43     ` Charles C. Berry
  2015-05-25 12:17       ` Jacob Gerlach
  1 sibling, 1 reply; 7+ messages in thread
From: Charles C. Berry @ 2015-05-24 19:43 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Rasmus

On Sun, 24 May 2015, Nicolas Goaziou wrote:

> Rasmus <rasmus@gmx.us> writes:
>
>> It's a special block, so e.g. org-latex-special-block.  But contents is
>> already transcoded by the time in arrives to e.g. org-latex-special-block.
>> To the extend this should be fixed, one way would be to allow a raw option
>> to special blocks (also needed for e.g. #+{begin,end}_equation) and have
>> babel insert it as needed.  I don't know how easy this is.
>
> I don't think a ":raw" option for special blocks is worth implementing.
>
> There are two types or "raw" contents: "protected raw" (i.e., verbatim
> contents) and "export-specific raw" (i.e., target language code). For
> the former, we already have example blocks (or fixed-width areas) and
> for the latter, export blocks.
>
> A third category exists, "multi-language raw", in which, I think, only
> the most trivial cases (those you never really need in practice) would
> fit.
>
> The OP wants special "protected raw" for LaTeX back-end. We could
> provide a special attribute for this, e.g.,
>
>  #+ATTR_LATEX: :environment "my-verbatim"
>  #+BEGIN_EXAMPLE
>  ... stuff...
>  #+END_EXAMPLE
>
> But this is really only a shortcut for
>
>  #+BEGIN_my-verbatim
>  #+BEGIN_LATEX
>  stuff
>  #+END_LATEX
>  #+END_my-verbatim
>
> WDYT?

Currently, :wrap allows this:

#+begin_src emacs-lisp :wrap "src latex :wrap my-verbatim"  :exports results
"stuff\nmore stuff"
#+end_src

which exports as

,----
| \begin{my-verbatim}
| stuff
| more stuff
| \end{my-verbatim}
`----

which is what was wanted (courtesy of ob-latex.el).

Is that enough?

HTH,

Chuck

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

* Re: Treat custom environment as verbatim on export
  2015-05-24 19:43     ` Charles C. Berry
@ 2015-05-25 12:17       ` Jacob Gerlach
  0 siblings, 0 replies; 7+ messages in thread
From: Jacob Gerlach @ 2015-05-25 12:17 UTC (permalink / raw)
  To: Org-mode

Hello,

On Sun, May 24, 2015 at 3:43 PM, Charles C. Berry <ccberry@ucsd.edu> wrote:
> Currently, :wrap allows this:
>
> #+begin_src emacs-lisp :wrap "src latex :wrap my-verbatim"  :exports results
...

This is sufficient for my use case. Thanks for the tip.

A special block ":raw" parameter, as Rasmus suggested, is what I was
really asking for (without realizing it), but as Nicolas said it isn't
worth implementing, Charles's solution works fine.

While obvious in hindsight, it didn't occur to me that marking the
results as LaTeX would protect them from interpretation just as
"verbatim" does.

Thanks for the help,
Jake

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

end of thread, other threads:[~2015-05-25 12:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-23  3:09 Treat custom environment as verbatim on export Jacob Gerlach
2015-05-23  9:48 ` Rasmus
2015-05-24 15:29   ` Nicolas Goaziou
2015-05-24 17:29     ` Rasmus
2015-05-24 19:43     ` Charles C. Berry
2015-05-25 12:17       ` Jacob Gerlach
2015-05-23 16:32 ` Charles C. Berry

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