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
Related
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"))
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"))
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"))
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.
I would like to see examples of how to setup perforce, using the config file functionality where emacs is used as the diff and merge programs (P4DIFF and P4MERGE settings). Even better if this is on Windows.
I'm also struggling with getting the P4EDITOR to work correctly when using emacsclientw, specifically specifying the alternate-editor functionality.
Any tips, suggestions, example configs are very welcome.
Here's a different trick I used to use. It adds a few command line options to emacs so that you can do diffs and merges in a new emacs instance (again using ediff).
;; -diff
(defun command-line-diff (switch)
(let ((file1 (pop command-line-args-left))
(file2 (pop command-line-args-left)))
(ediff file1 file2)))
(add-to-list 'command-switch-alist '("-diff" . command-line-diff))
;; -merge
(defun command-line-merge (switch)
(let ((base (pop command-line-args-left))
(sccs (pop command-line-args-left))
(mine (pop command-line-args-left))
(merg (pop command-line-args-left)))
(ediff-merge-with-ancestor sccs mine base () merg)))
(add-to-list 'command-switch-alist '("-merge" . command-line-merge))
Just put that in your .emacs file. Then you can set your P4DIFF program to be emacs -diff and your P4MERGE program to be emacs -merge.
I'm assuming you're already using p4.el.
Here's a function that will allow you to set your p4-client-config easily:
(defun p4-go (config)
(interactive
(list (read-file-name "P4 Config file: "
(concat (getenv "HOME") "/etc/perforce/")
""
t)))
(p4-set-client-config (expand-file-name config))
t)
Then I just run M-x p4-go <RET> conf <RET>.
My ~/etc/perforce/conf file looks like:
P4CLIENT=ewarmenhoven-ppd
P4PORT=perforce.netflix.com:1666
P4USER=ewarmenhoven
P4EDITOR=emacsclient
P4DIFF=diff -dupU8
P4MERGE=~/bin/emerge
The emerge merge program is just a short little shell script that calls emacsclient appropriately:
#!/bin/bash
base=$1
sccs=$2
mine=$3
merg=$4
emacsclient -e "(ediff-merge-files-with-ancestor \"$base\" \"$sccs\" \"$mine\" () \"$merg\")"
emacsclient "$merg"
If you're using cygwin it should work just fine.
For doing diffs, if it's running from the shell then I want the output in the shell, hence just using normal diff. If it's not, I use p4-ediff, which is bound to C-x p - by default.
The awesome answer by Eric doesn't work properly in latest emacs because of welcome screen. In order to hide the welcome screen (so that you may get the diff properly) please refer Unable to hide welcome screen in Emacs.
Another nifty setting which opens the diff in regular vertical mode is setting the below config variable
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(ediff-split-window-function (quote split-window-horizontally)))