emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Exporting Source Blocks with Symbols
@ 2016-01-14  4:45 Michael Gauland
  2016-01-17 20:10 ` Michael Gauland
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Gauland @ 2016-01-14  4:45 UTC (permalink / raw)
  To: emacs-orgmode

I've become fond of using Greek symbols in my R code (mu, sigma, etc). R
handles these just fine, but most of them disappear in the listing when I
export to LaTeX (lower-case mu comes through OK). I think the basic problem
is the the listings package can't handle the characters. I've come across
some ideas for coping with this in LaTeX, but they involve modifying the
source (e.g., escaping the symbols to math mode). Of course if I do that, R
won't know what to do with the characters.

Any suggestions? Does babel provide any hooks for pre-processing source
blocks for export? I didn't find any, but I often miss what's right in front
of me (just ask my wife!).

Kind Regards,
Michael Gauland

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

* Re: Exporting Source Blocks with Symbols
  2016-01-14  4:45 Exporting Source Blocks with Symbols Michael Gauland
@ 2016-01-17 20:10 ` Michael Gauland
  2016-01-20  2:26   ` Grant Rettke
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Gauland @ 2016-01-17 20:10 UTC (permalink / raw)
  To: emacs-orgmode

Just following up with my solution, in case anyone else is interested
(thanks to John Kitchin for pointing me in the right direction). First, I
should note that 'µ' exported correctly because I was using the unicode
element 'MICRO SYMBOL' instead of 'GREEK SMALL LETTER MU' (which looks the
same, but doesn't export).

The 'listings' package can only handle 8-bit characters, but you can tell it
to escape to LaTeX. The code block below adds a hook to escape the
characters I'm interested in, and adds the listing option to identify the
escape character (a symbol I've never used for anything else).

This code could certainly be improved, but it serves my needs, and may be
useful as a starting point for anyone trying to do something similar.
--Michael Gauland

#+BEGIN_SRC emacs-lisp :session :results value silent :exports none
;; Set up a filter to preserve greek symbols in code blocks
(setq org-export-filter-src-block-functions
      (list
	(lambda (text backend info)
	   (replace-regexp-in-string "\\([σβ]\\)" "§$\\1$§" text))))
	   
(setq org-latex-listings-options '(("escapechar" "§")))
#+END_SRC


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

* Re: Exporting Source Blocks with Symbols
  2016-01-17 20:10 ` Michael Gauland
@ 2016-01-20  2:26   ` Grant Rettke
  0 siblings, 0 replies; 3+ messages in thread
From: Grant Rettke @ 2016-01-20  2:26 UTC (permalink / raw)
  To: Michael Gauland; +Cc: emacs-orgmode@gnu.org

Thank you for sharing your solution.

My current solution: avoid the issue entirely and don't use Unicode in
your source code, use pretty-mode instead:
https://github.com/akatov/pretty-mode

A future option: switch from PDFLaTeX to XeLaTeX of LuaLaTeX.

Both are great. The latter is ideal, and does the "right thing" for
just about every language out there and if it doesn't, it is added
quickly.
Sincerely,

Grant Rettke


On Sun, Jan 17, 2016 at 2:10 PM, Michael Gauland <mikelygee@gmail.com> wrote:
> Just following up with my solution, in case anyone else is interested
> (thanks to John Kitchin for pointing me in the right direction). First, I
> should note that 'µ' exported correctly because I was using the unicode
> element 'MICRO SYMBOL' instead of 'GREEK SMALL LETTER MU' (which looks the
> same, but doesn't export).
>
> The 'listings' package can only handle 8-bit characters, but you can tell it
> to escape to LaTeX. The code block below adds a hook to escape the
> characters I'm interested in, and adds the listing option to identify the
> escape character (a symbol I've never used for anything else).
>
> This code could certainly be improved, but it serves my needs, and may be
> useful as a starting point for anyone trying to do something similar.
> --Michael Gauland
>
> #+BEGIN_SRC emacs-lisp :session :results value silent :exports none
> ;; Set up a filter to preserve greek symbols in code blocks
> (setq org-export-filter-src-block-functions
>       (list
>         (lambda (text backend info)
>            (replace-regexp-in-string "\\([σβ]\\)" "§$\\1$§" text))))
>
> (setq org-latex-listings-options '(("escapechar" "§")))
> #+END_SRC
>

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

end of thread, other threads:[~2016-01-20  2:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-14  4:45 Exporting Source Blocks with Symbols Michael Gauland
2016-01-17 20:10 ` Michael Gauland
2016-01-20  2:26   ` Grant Rettke

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