2
votes

I'm writing some French and I needed to make a few letters within a word bold, to highlight a particular syllable or difference between two very similar words so I followed the instruction of this thread "How to make part of a word bold in org-mode". I added the following lines at the bottom of my .emacs file (I'm in Windows 7 32-bit)

(setcar org-emphasis-regexp-components " \t('\"{[:alpha:]")
(setcar (nthcdr 1 org-emphasis-regexp-components) "[:alpha:]- \t.,:!?;'\")}\\")
(org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)

I saved and restarted the system but now, when I open the .org file, emacs doesn't recognize it as an .org file and doesn't apply any style or formatting. It sees it as a LaTeX file and doesn't allow me to export the contents with C-c C-e. Do I have to put those line in any particular order, for it to work with org-mode? I'm no elisp expert, I just a copy-paste the configuration code on-a-need-by-need case.

Please see the picture below. The typing is all white, how do I make it responsive? Should I move those new code lines up in my .emacs file? emacs doesn't see the file as an org file, instead as a LaTeX

CURRENT .emacs file

;;; Schlosser's .emacs
 (server-start)
 (add-hook 'LaTeX-mode-hook 'turn-on-reftex)
 (setq reftex-plug-into-AUCTeX t)

;;; a key for tilde symbol
(define-key key-translation-map (kbd "M-2") (kbd "~"))
;;; a key for backtick symbol
(define-key key-translation-map (kbd "M-6") "")
(define-key key-translation-map (kbd "M-9") (kbd "`"))

;; visual line word wrapping
 (global-visual-line-mode t)

;; ;;; Brent.Longborough's .emacs
 (setq inhibit-splash-screen t); Disable splash screen
 (setq visible-bell t); Flashes on error
 (show-paren-mode 1); Matches parentheses and such in every mode


;;; AUCTeX
;; Customary Customization, p. 1 and 16 in the manual, and http://www.emacswiki.org/emacs/AUCTeX#toc2
 (setq TeX-parse-self t); Enable parse on load.
 (setq TeX-auto-save t); Enable parse on save.
 (setq-default TeX-master nil)

 (setq TeX-PDF-mode t); PDF mode (rather than DVI-mode)

;activate Aspell, for all modes(?), not just TeX;
(add-to-list 'exec-path "C:/Program Files/Aspell/bin/")
(setq-default ispell-program-name "C:/Program Files/Aspell/bin/aspell.exe"); M-x ispell-change-dictionary RET to change dictionary
(setq ispell-dictionary "italiano"); Default dictionary. To change do M-x ispell-change-dictionary RET.
(require 'ispell) ;turn on dictionary check


;; (add-hook 'TeX-mode-hook 'flyspell-mode); Enable Flyspell mode for TeX modes such as AUCTeX. Highlights all misspelled words.
;; (add-hook 'emacs-lisp-mode-hook 'flyspell-prog-mode); Enable Flyspell program mode for emacs lisp mode, which highlights all misspelled words in comments and strings.

 (add-hook 'TeX-mode-hook
           (lambda () (TeX-fold-mode 1))); Automatically activate TeX-fold-mode.
;; (setq LaTeX-babel-hyphen nil); Disable language-specific hyphen insertion.

;; " expands into csquotes macros (for this to work babel must be loaded after csquotes).
;; (setq LaTeX-csquotes-close-quote "}"
;;       LaTeX-csquotes-open-quote "\\enquote{")

;from StackExchange question "AUCTeX preview font size too small"
 (set-default 'preview-scale-function 1.2)

;; LaTeX-math-mode http://www.gnu.org/s/auctex/manual/auctex/Mathematics.html
 (add-hook 'TeX-mode-hook 'LaTeX-math-mode)


(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ansi-color-faces-vector
   [default default default italic underline success warning error])
 '(custom-enabled-themes (quote (tango-dark)))
 '(org-format-latex-options
   (quote
    (:foreground default :background default :scale 1.2 :html-foreground "Black" :html-background "Transparent" :html-scale 1.0 :matchers
         ("begin" "$1" "$" "$$" "\\(" "\\["))))
 '(org-startup-with-latex-preview nil)
 '(preview-default-document-pt 10)
 '(show-paren-mode t)
 '(transient-mark-mode (quote (only . t))))

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )


;; yasnippet
(add-to-list 'load-path "~/.emacs.d/elpa/yasnippet-0.8.0")
(require 'yasnippet)
(setq yas-snippet-dirs '("~/.emacs.d/elpa/yasnippet-0.8.0/snippets"))
  ;(setq-default mode-require-final-newline nil) 
(yas-global-mode 1)
(defun disable-final-newline () (interactive) (set (make-local-variable 'require-final-newline) nil))

;; solving yasnippet and org-mode conflict as per manual
 (defun yas/org-very-safe-expand ()
   (let ((yas/fallback-behavior 'return-nil)) (yas/expand)))
(add-hook 'org-mode-hook
                    (lambda ()
                      (make-variable-buffer-local 'yas/trigger-key)
                      (setq yas/trigger-key [tab])
                      (add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
                      (define-key yas/keymap [tab] 'yas/next-field)))

;;emacs and SumatraPDF sync as per StackOverflow question "sync emacs auctex with SumatraPDF"
(setq TeX-PDF-mode t)
(setq TeX-source-correlate-mode t)
(setq TeX-source-correlate-method 'synctex)
(setq TeX-view-program-list
   '(("Sumatra PDF" ("\"C:/Program Files/SumatraPDF/SumatraPDF.exe\" -reuse-instance" (mode-io-correlate " -forward-search %b %n ") " %o"))))

(eval-after-load 'tex
  '(progn
     (assq-delete-all 'output-pdf TeX-view-program-selection)
     (add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF"))))


;code taken from SX "Cleveref: AUCTeX and RefTeX set-up"
(eval-after-load
    "latex"
  '(TeX-add-style-hook
    "cleveref"
    (lambda ()
      (if (boundp 'reftex-ref-style-alist)
      (add-to-list
       'reftex-ref-style-alist
       '("Cleveref" "cleveref"
         (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
      (reftex-ref-style-activate "Cleveref")
      (TeX-add-symbols
       '("cref" TeX-arg-ref)
       '("Cref" TeX-arg-ref)
       '("cpageref" TeX-arg-ref)
       '("Cpageref" TeX-arg-ref)))))


;; Org mode and Beamer export
(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"))
(setq org-src-preserve-indentation t)

;Python
(setq python-shell-interpreter "C:\Python27")


; allow bold or italics for parts of a word, from StakOverflow discussion "How to make part of a word bold in org-mode?"
 (setcar org-emphasis-regexp-components " \t('\"{[:alpha:]")
 (setcar (nthcdr 1 org-emphasis-regexp-components) "[:alpha:]- \t.,:!?;'\")}\\")
 (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)

underscore after options in org preamble

New screenshots

What I'm doing is writing and editing some French notes in Org-mode. When I'm done with a set of lessons, export the vocab.org file with C-c C-e, choose to export only the Body (C-b), and turn it into vocab.tex with l l. Once vocab.tex is produced, I type \input{vocab} inside vocab-main.tex which I have prepared previously and that contains all the page and font formatting (in LaTeX). Finally I compile vocab-main.tex with pdfLaTeX and get the pdf!

I don't know if this is the best way to produce a good-looking pdf, I'm open to suggestion. Anyway, as you can see, at the bottom of vocab.org I have the LaTeX "tags" that allow vocab.tex to work with vocab-main.tex as the master file.

vocab.org structure

2

2 Answers

2
votes

The code you have added should not have changed emacs from interpreting *.org files as org mode files. I suspect something else is broken in your .emacs init.

  1. Try running emacs with --debug-init. This should show if you have any problems in your init file

  2. Remove the lines you added and see if things return to normal.

  3. Post your current org mode configuration. You probably need to ensure that the lines you have added are added as part of an org-mode startup hook - at the very least, you probably need to ensure that the call to org-set-emph-re is called after your org has been loaded and initialised.

  4. Create a very basic org-mode file with just what you need and no more - remove all the additonal #+ options stuff. Get the basic org emphasis functionality working first and then add this staff back later.

0
votes

EDIT: It looks like I was barking up the wrong tree regarding the org-reload suggestion. Sorry about that.

The "Local variables list is not properly terminated" error suggests that it has something to do with the local variables block inside your final LaTeX block. So, without your customizations, I created a file with a .org suffix and the following text:

#+BEGIN_LATEX
%%% Local Variables:
%%% mode: latex
%%% End:
#+END_LATEX

And I see exactly the same behavior you report, with latex-mode being used instead of org-mode. So what's happening is that Emacs is seeing the local variable block, even though you only want it to apply to the exported file, and overriding the usual determination of the major mode based on file suffix. See the manual (here and here) for more details.

As a workaround, I can add a form feed (^L) after this block to make Emacs ignore this block (as it will only search the last page of the file), but I don't know how this will affect export. Alternatively, since export should produce a .tex file, you probably don't need the mode line here. The TeX-master line isn't a problem in any case.

Of course, none of this explains your actual error, since I don't get that error, and all of this looks to me like a perfectly well-formed local variables block. There may be something else happening as well.

END EDIT


I don't see how this would cause the behavior you're seeing, but I do note that org-emphasis-regexp-components says in its documentation:

You need to reload Org or to restart Emacs after customizing this.

I have some code in my own init file modifying org-emphasis-alist, which has the same warning, and I've found that I do need to call org-reload after making my changes in order to make everything work properly. (One of these days I'm planning on poking around the source to see if I can avoid loading Org mode twice every time I restart Emacs, but I haven't gotten around to that yet.) I think it's possible to avoid this sort of thing with the customize facility, but that doesn't work very well when you want to make changes to a variable relative to its default value, as here.

I would try inserting (org-reload) after your changes and see if that fixes it. If not, Tim's advice is good, and I would also suggest to look through your messages buffer and see if there are any errors reported that might give you a place to start.