emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Custom formatting during export
@ 2014-09-03 13:36 Gabe Becker
  2014-09-03 15:41 ` Thorsten Jolitz
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Gabe Becker @ 2014-09-03 13:36 UTC (permalink / raw)
  To: emacs-orgmode, Julian Gehring

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

orgmode developers and power-users,

I'd like to be able to declare custom entities (apologies if I'm using that
term incorrectly) within the text of an orgmode document which I can
specify custom formatting for when my .org is exported, e.g. to PDF or HTML.

I have a background in Docbook, so the analogue there would be defining a
custom xml tag and then extending the XSL files to handle it as desired.
Please see the following snippet:


* section title

Here is some text, but I want [specialthing: this bit here] to be formatted
differently than [newanddifferent: this other big over here].


Where I would have defined specific custom formatting rules for
"specialthing" and "newanddifferent" type entities.

Is there a way to do this in orgmode? If not, it seems like it would be a
very useful feature (at least to me:) ). Note: I don't care about the
syntax as long as the result is the same.

Thanks for your help,
~G
-- 
Computational Biologist
Genentech Research

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

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

* Re: Custom formatting during export
  2014-09-03 13:36 Custom formatting during export Gabe Becker
@ 2014-09-03 15:41 ` Thorsten Jolitz
  2014-09-03 16:22 ` Richard Lawrence
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Thorsten Jolitz @ 2014-09-03 15:41 UTC (permalink / raw)
  To: emacs-orgmode

Gabe Becker <becker.gabe@gene.com> writes:

> orgmode developers and power-users,
>
> I'd like to be able to declare custom entities (apologies if I'm using
> that term incorrectly) within the text of an orgmode document which I
> can specify custom formatting for when my .org is exported, e.g. to
> PDF or HTML.
>
> I have a background in Docbook, so the analogue there would be
> defining a custom xml tag and then extending the XSL files to handle
> it as desired. Please see the following snippet:
>
> * section title
> Here is some text, but I want [specialthing: this bit here] to be
> formatted differently than [newanddifferent: this other big over
> here].
>
> Where I would have defined specific custom formatting rules for
> "specialthing" and "newanddifferent" type entities.
>
> Is there a way to do this in orgmode? If not, it seems like it would
> be a very useful feature (at least to me:) ). Note: I don't care about
> the syntax as long as the result is the same.

After an org buffer is parsed, the complete document is available as
nested list (parse tree), containing org elements and objects:

,----[ C-h v org-element-all-elements RET ]
| org-element-all-elements is a variable defined in `org-element.el'.
| Its value is (babel-call center-block clock comment comment-block
| diary-sexp drawer dynamic-block example-block fixed-width
| footnote-definition headline horizontal-rule inlinetask item keyword
| latex-environment node-property paragraph plain-list planning
| property-drawer quote-block section special-block src-block table
| table-row verse-block)
| 
| Documentation: Complete list of element types.
`----

,----[ C-h v org-element-all-objects RET ]
| org-element-all-objects is a variable defined in `org-element.el'.
| Its value is (bold code entity export-snippet footnote-reference
| inline-babel-call inline-src-block italic line-break latex-fragment
| link macro radio-target statistics-cookie strike-through subscript
| superscript table-cell target timestamp underline verbatim)
| 
| Documentation:
| Complete list of object types.
`----

The exporters have complete access to these elements, and define
dedicated functions for transforming each of them to the output format
(LATEX, HTML ...). 

So if you want latex output, but special treatment for a few elements,
the way to go is to define a new export backend that derives from latex:

,----[ C-h f org-export-define-derived-backend RET ]
| org-export-define-derived-backend is a compiled Lisp function in
| `ox.el'.
| 
| (org-export-define-derived-backend CHILD PARENT &rest BODY)
| 
| Create a new back-end as a variant of an existing one.
| 
| CHILD is the name of the derived back-end.  PARENT is the name of
| the parent back-end.
| 
| BODY can start with pre-defined keyword arguments.  The following
| keywords are understood:
| 
|   :export-block
| 
|     String, or list of strings, representing block names that
|     will not be parsed.  This is used to specify blocks that will
|     contain raw code specific to the back-end.  These blocks
|     still have to be handled by the `special-block' type
|     translator.
| 
|   :filters-alist
| 
|     Alist of filters that will overwrite or complete filters
|     defined in PARENT back-end.  See `org-export-filters-alist'
|     for a list of allowed filters.
| 
|   :menu-entry
| 
|     Menu entry for the export dispatcher.  See
|     `org-export-define-backend' for more information about the
|     expected value.
| 
|   :options-alist
| 
|     Alist of back-end specific properties that will overwrite or
|     complete those defined in PARENT back-end.  Refer to
|     `org-export-options-alist' for more information about
|     structure of the values.
| 
|   :translate-alist
| 
|     Alist of element and object types and transcoders that will
|     overwrite or complete transcode table from PARENT back-end.
|     Refer to `org-export-define-backend' for detailed information
|     about transcoders.
| 
| As an example, here is how one could define "my-latex" back-end
| as a variant of `latex' back-end with a custom template function:
| 
|   (org-export-define-derived-backend 'my-latex 'latex
|      :translate-alist '((template . my-latex-template-fun)))
| 
| The back-end could then be called with, for example:
| 
|   (org-export-to-buffer 'my-latex "*Test my-latex*")
`----

-- 
cheers,
Thorsten

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

* Re: Custom formatting during export
  2014-09-03 13:36 Custom formatting during export Gabe Becker
  2014-09-03 15:41 ` Thorsten Jolitz
@ 2014-09-03 16:22 ` Richard Lawrence
  2014-09-03 16:26 ` Julian Gehring
  2014-09-03 16:44 ` Thomas S. Dye
  3 siblings, 0 replies; 5+ messages in thread
From: Richard Lawrence @ 2014-09-03 16:22 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: becker.gabe

Hi Gabe,

Gabe Becker <becker.gabe@gene.com> writes:

> * section title
>
> Here is some text, but I want [specialthing: this bit here] to be formatted
> differently than [newanddifferent: this other big over here].
>
>
> Where I would have defined specific custom formatting rules for
> "specialthing" and "newanddifferent" type entities.
>
> Is there a way to do this in orgmode? If not, it seems like it would be a
> very useful feature (at least to me:) ). Note: I don't care about the
> syntax as long as the result is the same.

Based on the syntax you chose for your example, you might be looking for
custom link types; see the documentation for the org-add-link-type
function:
------------------------------------------------------------------------------
(org-add-link-type TYPE &optional FOLLOW EXPORT)

Add TYPE to the list of `org-link-types'.
Re-compute all regular expressions depending on `org-link-types'

FOLLOW and EXPORT are two functions.

FOLLOW should take the link path as the single argument and do whatever
is necessary to follow the link, for example find a file or display
a mail message.

EXPORT should format the link path for export to one of the export formats.
It should be a function accepting three arguments:

  path    the path of the link, the text after the prefix (like "http:")
  desc    the description of the link, if any, or a description added by
          org-export-normalize-links if there is none
  format  the export format, a symbol like `html' or `latex' or `ascii'..

The function may use the FORMAT information to return different values
depending on the format.  The return value will be put literally into
the exported file.  If the return value is nil, this means Org should
do what it normally does with links which do not have EXPORT defined.
------------------------------------------------------------------------------

You could define a custom link type for "specialthing", and then use the
export parameter to provide a function that will export the path 
of the link in a backend-specific way.  Then you would write

blah blah [[specialthing:whatever-path]] blah blah 

I'm sure there are good examples of how to do this on Worg, but I cannot
seem to find them at the moment...

If you need to do something more complicated than what custom link types
allow, Thorsten's suggestions are the place to start: Org has a lot of
ways to customize export output.
 
Best,
Richard

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

* Re: Custom formatting during export
  2014-09-03 13:36 Custom formatting during export Gabe Becker
  2014-09-03 15:41 ` Thorsten Jolitz
  2014-09-03 16:22 ` Richard Lawrence
@ 2014-09-03 16:26 ` Julian Gehring
  2014-09-03 16:44 ` Thomas S. Dye
  3 siblings, 0 replies; 5+ messages in thread
From: Julian Gehring @ 2014-09-03 16:26 UTC (permalink / raw)
  To: Gabe Becker; +Cc: emacs-orgmode

Hi Gabe,

Macro replacements [[http://orgmode.org/manual/Macro-replacement.html]] 
should be what you are looking for.

For example, the macro

     #+MACRO: pkg  $1

would be called by

     {{{pkg(PkgName)}}}

You can also use this to format your input for one or multiple backends

     #+MACRO: M @@latex:\$1{@@$2@@latex:}@@

Let me know if this helps.

Best
Julian


On 03.09.2014 06:36, Gabe Becker wrote:
> orgmode developers and power-users,
>
> I'd like to be able to declare custom entities (apologies if I'm using
> that term incorrectly) within the text of an orgmode document which I
> can specify custom formatting for when my .org is exported, e.g. to PDF
> or HTML.
>
> I have a background in Docbook, so the analogue there would be defining
> a custom xml tag and then extending the XSL files to handle it as
> desired. Please see the following snippet:
>
>
> * section title
> Here is some text, but I want [specialthing: this bit here] to be
> formatted differently than [newanddifferent: this other big over here].
>
>
> Where I would have defined specific custom formatting rules for
> "specialthing" and "newanddifferent" type entities.
>
> Is there a way to do this in orgmode? If not, it seems like it would be
> a very useful feature (at least to me:) ). Note: I don't care about the
> syntax as long as the result is the same.
>
> Thanks for your help,
> ~G
> --
> Computational Biologist
> Genentech Research

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

* Re: Custom formatting during export
  2014-09-03 13:36 Custom formatting during export Gabe Becker
                   ` (2 preceding siblings ...)
  2014-09-03 16:26 ` Julian Gehring
@ 2014-09-03 16:44 ` Thomas S. Dye
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas S. Dye @ 2014-09-03 16:44 UTC (permalink / raw)
  To: Gabe Becker; +Cc: Julian Gehring, emacs-orgmode

Aloha Gabe,

Gabe Becker <becker.gabe@gene.com> writes:

> orgmode developers and power-users,
>
> I'd like to be able to declare custom entities (apologies if I'm using that
> term incorrectly) within the text of an orgmode document which I can
> specify custom formatting for when my .org is exported, e.g. to PDF or HTML.
>
> I have a background in Docbook, so the analogue there would be defining a
> custom xml tag and then extending the XSL files to handle it as desired.
> Please see the following snippet:
>
>
> * section title
>
> Here is some text, but I want [specialthing: this bit here] to be formatted
> differently than [newanddifferent: this other big over here].
>
>
> Where I would have defined specific custom formatting rules for
> "specialthing" and "newanddifferent" type entities.
>
> Is there a way to do this in orgmode? If not, it seems like it would be a
> very useful feature (at least to me:) ). Note: I don't care about the
> syntax as long as the result is the same.
>
> Thanks for your help,
> ~G
> -- 
> Computational Biologist
> Genentech Research
> orgmode developers and power-users,

Macros, links, derived back-ends -- so many ways to achieve what you
want.  Here is another:

@@html:<b>@@bold text@@html:</b>@@

#+HTML: Literal HTML code for export

#+BEGIN_HTML
 All lines between these markers are exported literally
#+END_HTML

For pdf export via LaTeX there are @@latex, #+LATEX, and #+BEGIN_LATEX
... #+END_LATEX.

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

end of thread, other threads:[~2014-09-03 16:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-03 13:36 Custom formatting during export Gabe Becker
2014-09-03 15:41 ` Thorsten Jolitz
2014-09-03 16:22 ` Richard Lawrence
2014-09-03 16:26 ` Julian Gehring
2014-09-03 16:44 ` Thomas S. Dye

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