Emacs org-mode latex - simply switch between pdflatex, xelatex and lualatex - emacs

Using latexmk I've tested the following setup
(setq org-latex-pdf-process '("latexmk %f -output-directory=%o -%latex"))
using the example below
#+TITLE: My Paper
#+AUTHOR: Jane Doe
#+DATE:
#+OPTIONS: toc:nil num:nil
#+LATEX_COMPILER: xelatex
#+LATEX_HEADER: \usepackage{fontspec}
#+LATEX_HEADER: \setsansfont{Acme}
* Title
- Text
and it works for xelatex und lualatex, but not for pdflatex because latexmk fails with the option -pdflatex, which would require a string.
Is there any easy way to fix this issue? E.g. set org-latex-pdf-process based on a the selection of the LATEX_COMPILER using a hook?

I found the following solution, which works for me
(setq org-latex-pdf-process (list "latexmk -pdflatex='%latex -shell-escape -interaction nonstopmode' -pdf -output-directory=%o %f"))

Related

How to make org-mode use bibulous.py instead of biber?

I would like to export my Org documents to a PDF and have bibulous.py format the bibliography. For this I use the command C-c C-e l p aka org-latex-pdf-process. Here is how I have adapted the command to my needs
(setq org-latex-pdf-process
(list "lualatex -shell-escape -interaction nonstopmode %f"
(concat "python C:/pythonpath/bibulous.py " "my_document_name" ".aux")
"lualatex -shell-escape -interaction nonstopmode %f"
"lualatex -shell-escape -interaction nonstopmode %f"))
This works so far, but only for my test document with the name my_document_name. To keep things general, there should be a function here that uses the current buffer name. I tried
python C:/pythonpath/bibulous.py %f.aux
but it does not work. I suspect that the variable %f contains the extension .tex (is there a way to see what exactly was called? the *Messages* buffer does not show this).
I have also tried the following
(concat "python C:/pythonpath/bibulous.py " (file-name-sans-extension buffer-file-name) ".aux")
however, it seems that this variable is set when Emacs is launched, and does not access the actual buffer name during runtime.
You should check the doc of org-latex-pdf-process by C-h v org-latex-pdf-process
Commands to process a LaTeX file to a PDF file.
This is a list of strings, each of them will be given to the
shell as a command. %f in the command will be replaced by the
relative file name, %F by the absolute file name, %b by the file
base name (i.e. without directory and extension parts), %o by the
base directory of the file, %O by the absolute file name of the
output file, %latex is the LaTeX compiler (see
org-latex-compiler), and %bib is the BibTeX-like compiler (see
org-latex-bib-compiler).
...
So all you need is
(setq org-latex-pdf-process
'("lualatex -shell-escape -interaction nonstopmode %f"
"python C:/pythonpath/bibulous.py %b.aux"
"lualatex -shell-escape -interaction nonstopmode %f"
"lualatex -shell-escape -interaction nonstopmode %f"))

Emacs polymode for Markdown and Python

I use the python3 pweave library (http://mpastell.com/pweave/usage.html) for literate programming.
pweave uses as text mode markdown, as code mode python3,
and it is possible to use noweb (https://en.wikipedia.org/wiki/Noweb) literate programming syntax.
For correct syntax highlighting in emacs I aimed to use the polymode library (https://polymode.github.io/ and https://github.com/polymode).
I use emacs version26.1.
And I was able to install polymode from melpa.
Unfortunate there is no pre-existing polymode for
host-mode: markdown, inner-mode: python3, syntax: noweb
so I tried, based on documentation and the existing code, to write my one
poly-pweave-mode, by putting the following lisp code into my .emacs file.
(require 'polymode-classes)
(defcustom pm-host/pweave-text
(pm-host-chunkmode :name "pweave-text"
:mode 'markdown-mode)
"markdown host chunkmode"
:group 'poly-hostmodes
:type 'object)
(defcustom pm-inner/pweave-code
(pm-inner-chunkmode :name "pweave-code"
:head-matcher "^[ \t]*<<\\(.*\\)>>="
:tail-matcher "^[ \t]*#.*$"
:mode 'python-mode)
"noweb static python3 inner chunkmode."
:group 'poly-innermodes
:type 'object)
(define-polymode poly-pweave-mode
:hostmode 'pm-host/pweave-text
:innermode 'pm-inner/pweave-code)
(add-to-list 'auto-mode-alist '("\\.pymd" . poly-pweave-mode))
But somehow emacs is not eating this.
When I open emacs I get the following error:
Warning (initialization): An error occurred while loading `/Users/abc/.emacs':
Symbol's function definition is void: pm-host-chunkmode
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
What do I wrong?
How I could get the desired polymode running?
This is the solution how to specify a markdown-python3-noweb polymode
;; define pwn polymode
(require 'poly-noweb)
(require 'poly-markdown)
(defcustom pm-inner/noweb-python
(clone pm-inner/noweb
:name "noweb-python"
:mode 'python-mode)
"Noweb for Python"
:group 'poly-innermodes
:type 'object)
(define-polymode poly-pweave-mode poly-markdown-mode
:innermodes '(pm-inner/noweb-python :inherit))
(add-to-list 'auto-mode-alist '("\\.pymd" . poly-pweave-mode))
My thank goes to Vitalie Spinu, the author of the polymode package, who helped me resolving this question!
For a detailed discussion have a look at polymode issue 180 at github.
Alternatively I found this post at emacs stack exchange: https://emacs.stackexchange.com/questions/20136/pythontex-and-auctex So, following this post, this is the solution to get to a markdown-python3-noweb mmm-mode
;; define pwn multi major modes mode
(require 'mmm-auto)
(mmm-add-classes
'((noweb-python
:submode python-mode
:face mmm-default-submode-face
:front "^<<.*>>=\n"
:back "^#$")))
(setq mmm-global-mode 'maybe)
(mmm-add-mode-ext-class 'markdown-mode nil 'noweb-python)
(add-to-list 'auto-mode-alist '("\\.pymd" . markdown-mode))
My thank belongs to Jean Pierre, whose detailed explanation in the post made it a piece of cake to get it running for my case!

org mode pdf export error "Wrong type argument: sequencep 108"

I'm using emacs version 25.2 on a MacBook Pro (OS X 10.12). When I try to export an org document to pdf, I get the message above. If I export to latex, it works OK, and I can then use pdflatex to create the pdf I expect.
I must have set something wrong, but I can't work out what!
Exporting to other formats, e.g., ODT, html, works as expected.
Thanks very much!
You might check the value of the variable org-latex-pdf-process. You can do that with C-h v. It may be doing something different than what you are doing by hand. Mine for example reads:
(setq org-latex-pdf-process '("pdflatex -interaction nonstopmode %f" "biber %b" "pdflatex -interaction nonstopmode %f" "pdflatex -interaction nonstopmode --synctex=-1 %f"))

Export org-mode code block and result with different styles

I am preparing a presentation using org-mode and babel, and want to export to beamer pdf.
In the output, the source code and the results are with the same style (verbatim in latex). Thus it is difficult to distinguish them.
Would it be possible to export source code and results with different styles (preferably different color)?
Thanks a lot!
You could use the minted LaTeX package to syntax highlight the source code:
C-h v org-latex-listings
...
(setq org-latex-listings 'minted)
causes source code to be exported using the minted package as
opposed to listings. If you want to use minted, you need to add
the minted package to `org-latex-packages-alist', for example
using customize, or with
(require 'ox-latex)
(add-to-list 'org-latex-packages-alist '("" "minted"))
In addition, it is necessary to install pygments
(http://pygments.org), and to configure the variable
`org-latex-pdf-process' so that the -shell-escape option is
passed to pdflatex.
The minted choice has possible repercussions on the preview of
latex fragments (see `org-preview-latex-fragment'). If you run
into previewing problems, please consult
http://orgmode.org/worg/org-tutorials/org-latex-preview.html
I have this in my init file:
(require 'ox-latex)
(add-to-list 'org-latex-packages-alist '("" "minted"))
(setq org-latex-listings 'minted)
(setq org-latex-pdf-process
'("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
There are different color-themes you can use with minted, for example you could put this option into your org file to use "monokai":
#+LaTeX_HEADER: \usemintedstyle{monokai}
to get a list of the supported styles from pygmentize:
pygmentize -L styles

How to set the command of View by default with a real filename?

I have this line in my .emacs:
(setq TeX-view-program-list '(("Okular" "okular --unique %u")))
When I type C-c C-c, then View, then the command turns out to be okular --unique %u, however, I would like it to be okular-unique filename.pdf
Could anyone help? Thank you very much
I think you should have something like this for your config:
(setq TeX-view-program-selection
'((output-pdf "PDF Viewer")))
(setq TeX-view-program-list
'(("PDF Viewer" "okular %o")))
I'm not sure if this okular-unique is a program name - it that case just replace okular with okular-unique.