在 org-mode 中导出到 beamer 时,我遇到了一个奇怪的问题。我使用 minted 导出 python。但由于某种我不知道的原因,我有时会丢失缩进。例如:
** NDVI is SciPy 1/2
Since operations on array are element-wise, the computation of the
NDVI is really simple.
#+BEGIN_SRC python :exports code
import scipy as sp
#def compute_ndvi(im,r=3,ir=4):
'''
The function computes the NVDI of an image.
Parameters
----------
im: the image cube
r: the indice of the band that corresponds to the red
ir: the indice of the band that corresponds to the infrared
Returns
-------
ndvi: the NDVI, an float-array
'''
[nl,nc,nb]=im.shape
if nb <2:
print "Two bands are needed to compute the NDVI"
return None
else:
ndvi = (im[:,:,ir-1]-im[:,:,r-1])/(im[:,:,ir-1]+im[:,:,r-1])
return ndvi
#+END_SRC
将产生正确的输出
但如果我取消注释该函数的定义:
import scipy as sp
def compute_ndvi(im,r=3,ir=4):
'''
The function computes the NVDI of an image.
Parameters
----------
im: the image cube
r: the indice of the band that corresponds to the red
ir: the indice of the band that corresponds to the infrared
Returns
-------
ndvi: the NDVI, an float-array
'''
[nl,nc,nb]=im.shape
if nb <2:
print "Two bands are needed to compute the NDVI"
return None
else:
ndvi = (im[:,:,ir-1]-im[:,:,r-1])/(im[:,:,ir-1]+im[:,:,r-1])
return ndvi
输出不正确
babel 生成的文件对于每种情况都适用,并且编译 org mode width pdflatex 生成的 tex 给出了相同的结果。
我的ini.el如下:
;; Org mode and bearmer export
(require 'org-install)
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(setq system-time-locale "C")
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
(setq org-agenda-files (list "~/Documents/Org_Files/todo.org"))
(require 'ox-beamer)
(setq org-latex-to-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"))
(defun my-beamer-bold (contents backend info)
(when (eq backend 'beamer)
(replace-regexp-in-string "\\`\\\\[A-Za-z0-9]+" "\\\\textbf" contents)))
(add-to-list 'org-export-filter-bold-functions 'my-beamer-bold)
(setq org-src-fontify-natively t)
(org-babel-do-load-languages
'org-babel-load-languages
'((python . t)
(latex . t)))
(setq org-confirm-babel-evaluate nil)
(setq org-babel-python-command "ipython --pylab --pdb --nosep --classic --no-banner --no-confirm-exit")
(setq org-latex-listings 'minted)
(setq org-latex-minted-options
'(("fontsize" "\\footnotesize")("bgcolor" "black")("obeytabs" "true")))
(require 'ox-latex)
(setq org-src-fontify-natively t)
(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"))
我不明白为什么我会丢失格式。您有什么想法吗?