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

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

Related

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

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

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

One-shot command to knit and latexmk under Emacs + AUCtex

I want to knit AND latexmk Knitr documents using one AUCtex command.
I don't know how to code in lisp, and web search didn't turn up anything like this.
I have something close. The extension of the file needs to be changed for latexmk.
Any help will be appreciated.
Following line is for my .emacs file.
(add-hook 'LaTeX-mode-hook (lambda () (push '
("KnitrLaTeX" "Rscript -e \"library(knitr)\; knit('%s')\" && latexmk -pdf %s"
TeX-run-TeX nil t :help "Run knitr and latexmk on file")
TeX-command-list)))
When I run C-c C-c (KnitrLaTeX), emacs runs the following command:
Running `KnitrLaTeX' on `slides.Rnw' with ``Rscript -e "library(knitr); knit('slides.Rnw')" && latexmk -pdf slides.Rnw''
Which is wrong. It should read "... && latexmk -pdf slides.tex"
Thanks in advance.
It appears that you are having trouble with how the second usage of %s is being interpreted at the tail end of your compile command -- i.e., you want the second usage of %s to mean slides.tex instead of slides.Rnw.
Although I am not familiar with knit, I am familiar with creating custom variables for use with AUCTeX. Set forth below are some examples of how to create custom variables and add them to the TeX-expand-list.
Rather than of using %s for a second time (i.e., at the tail end of your compilation command), perhaps consider using %(tex-file-name) instead. This assumes that your *.tex file is open in the buffer with focus when you begin your compilation command -- i.e., the full file name will be inserted into your compilation command.
If you have a file with a different extension that is open in the buffer with focus when you run your compilation command, and if you want the base name to be the same (but with a different extension), then you would do something similar to the example of %(pdf-file-name) -- i.e., remove whatever extension is there and replace it with the new one.
(eval-after-load "tex" '(progn
(add-to-list 'TeX-expand-list '("%(tex-file-name)" (lambda ()
(concat "\"" (buffer-file-name) "\""))))
(add-to-list 'TeX-expand-list '("%(pdf-file-name)" (lambda ()
(concat
"\"" (car (split-string (buffer-file-name) "\\.tex"))
".pdf" "\""))))
(add-to-list 'TeX-expand-list '("%(line-number)" (lambda ()
(format "%d" (line-number-at-pos))))) ))

Emacs + Synctex + Skim: How to correctly set up synchronization? [none of the existing methods worked properly]

I'm working with GNU Emacs 23.3 (9.0) on Mac OS X 10.7.2. I would like to use synctex to jump between .tex and .pdf files. Although there are many different approaches on the web, none worked properly (I tried 8 different approaches...). I finally ended up with the rather simple approach described here: http://sourceforge.net/apps/mediawiki/skim-app/index.php?title=TeX_and_PDF_Synchronization
So my .emacs contains:
'(LaTeX-command "latex -synctex=1")
(require 'tex-site)
(add-hook 'TeX-mode-hook
(lambda ()
(add-to-list 'TeX-output-view-style
'("^pdf$" "."
"/Applications/Skim.app/Contents/SharedSupport/displayline -b %n %o %b")))
)
(server-start)
Of course, I also set up Skim (Preferences -> Sync -> checked "Check for file changes" and chose Preset: Emacs with command emacsclient and arguments --no-wait +%line "%file")
As you can see, I included the -b option to displayline. I can call displayline from the terminal and it opens the .pdf and displays the corresponding line with a yellow/highlighted bar. Still, nothing is displayed on the current line if I compile the document with latexmk -pvc -pdf from a shell within Emacs.app.
Question 1: How can I get this to work/How can I display the current line?
Question 2: Is it possible to have a "proper" forward search by clicking the .tex and jumping to the corresponding line in the .pdf document? How can I "click" in emacs? The standard CMD + shift + click does not work in emacs.
I also tried approaches using...
(setq TeX-source-correlate-method 'synctex)
(add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)
... but nothing changes.
I can CMD + shift + click in the .pdf and jump to the .tex, so that works.
The only directions which I haven't looked into are:
is this a latexmk problem? Most likely not, since latexmk explicitly displays pdflatex -interaction=nonstopmode -synctex=1 so synctex is recognized
is it a wrong skim preference setting? Maybe I have to adjust the arguments to emacsclient there (?)
Solution
Indeed latexmk is the problem. I finally figured out the following settings:
~/.emacs
;; make latexmk available via C-c C-c
;; Note: SyncTeX is setup via ~/.latexmkrc (see below)
(add-hook 'LaTeX-mode-hook (lambda ()
(push
'("latexmk" "latexmk -pdf %s" TeX-run-TeX nil t
:help "Run latexmk on file")
TeX-command-list)))
(add-hook 'TeX-mode-hook '(lambda () (setq TeX-command-default "latexmk")))
;; use Skim as default pdf viewer
;; Skim's displayline is used for forward search (from .tex to .pdf)
;; option -b highlights the current line; option -g opens Skim in the background
(setq TeX-view-program-selection '((output-pdf "PDF Viewer")))
(setq TeX-view-program-list
'(("PDF Viewer" "/Applications/Skim.app/Contents/SharedSupport/displayline -b -g %n %o %b")))
(server-start); start emacs in server mode so that skim can talk to it
~/.latexmkrc
$pdflatex = 'pdflatex -interaction=nonstopmode -synctex=1 %O %S';
$pdf_previewer = 'open -a skim';
$clean_ext = 'bbl rel %R-blx.bib %R.synctex.gz';
This perfectly allows to compile with latexmk as default on C-c C-c and C-c C-v opens Skim at the current line which is nicely highlighted. With CMD + shift + click in the .pdf, one can then jump back to the corresponding paragraph in the .tex file (thanks to server-start).
To enable the clicking feature of the sync, I added:
(add-hook 'LaTeX-mode-hook
(lambda () (local-set-key (kbd "<S-s-mouse-1>") #'TeX-view))
)
to my .emacs file.
NOTE: make sure that you are in PDF mode (use (setq TeX-PDF-mode t)).
When you press C-c C-v (which runs TeX-view) it should open Skim with the bar on the current line. This is what you set up with the TeX-output-view-style. You can't get that behaviour from latexmk -pvc since it doesn't know which line you are on. All latexmk knows is that the file changed. In order to do a forward search you need to run TeX-view.
You can bind CMD + shift + click to run TeX-view by adding
(define-key LaTeX-mode-map [M-S-mouse-1] 'TeX-view)
or possibly
(define-key LaTeX-mode-map [s-S-mouse-1] 'TeX-view)
to your TeX-mode-hook. It depends on your settings which you need, but can find out by pressing C-h C-k and then CMD+shift+click. Of course adding both shouldn't cause a problem.