I have a link abbreviation defined that just makes a file path relative to my org directory:
(setq org-link-abbrev-alist
`(
("orgdir" . ,(format "file://%s%%s" (file-name-as-directory org-directory)))
...
Unfortunately, links to image files no longer display inline:
This works:
[[~/org/foo/image.png]]
This doesn't:
[[orgdir:foo/image.png]]
Any way to fix this?
Solved: I wrote the abbreviation to resolve to a standard file:// URL format but org mode just wants file:. With org-directory equal to "~/org/", [[orgdir:foo/image.png]] resolves to [[file://~/org/foo/image.png]] when it should be [[file:~/org/foo/image.png]]. Changing the corresponding line in my init.el fixes it:
(setq org-link-abbrev-alist
`(
("orgdir" . ,(format "file:%s%%s" (file-name-as-directory org-directory)))
...
Related
Is it possible to completely disable the title, i.e. not even \title{}, when export org file to latex? I am using org mode to write paper the latex template provided by the publisher does not allow \title{} command appears before \begin{document}
I tried many solutions found online but neither of them works with the latex template I am using. Currently, I put #+BIND: org-latex-title-command " in my org file. From the source code in ox-latex, I found the following code inside org-latex-template (contents info):
;; Title and subtitle.
(let* ((subtitle (plist-get info :subtitle))
(formatted-subtitle
(when subtitle
(format (plist-get info :latex-subtitle-format)
(org-export-data subtitle info))))
(separate (plist-get info :latex-subtitle-separate)))
(concat
(format "\\title{%s%s}\n" title
(if separate "" (or formatted-subtitle "")))
(when (and separate subtitle)
(concat formatted-subtitle "\n"))))
Does this mean that there is no way to get rid of the \title{} command in the exported latex file?
Thanks for your assistance!
I came up with this little advice function that removes the \title{...} line from the output:
(defun my-org-latex-remove-title (str)
(replace-regexp-in-string "^\\\\title{.*}$" "" str))
(advice-add 'org-latex-template :filter-return 'my-org-latex-remove-title)
How can I get the folder in which org-mode is installed in emacs? Depending on the way it was installed, it will be different. Is there a variable which holds this value?
I would need it to access a file which is part of the org-mode installation.
I am not looking for a particular library, but an .R file, which is an R file which I want to load programmatically into R (from elisp code).
So using
(locate-library "ob-R")
"/Users/rainerkrug/.emacs.d/org-mode/lisp/ob-R.elc"
I would then have to use the following:
(concat (locate-library "ob-R") "/../etc/")
"/Users/rainerkrug/.emacs.d/org-mode/lisp/ob-R.elc/../etc/"
And I still have to get rid of the ob-R.elc
This works, but I am looking for a function which gives me the path
(IS-THERE-SOMETHING-LIKE-THIS "org")
"/Users/rainerkrug/.emacs.d/org-mode/"
Thanks
Emacs provides a rich set of file name manipulation functions which easily solve your problem:
(expand-file-name "../etc/R" (file-name-directory (locate-library "ob-R")))
M-x locate-library RET org RET
or, if you would like to open:
M-x find-library RET org RET
You can use this:
(org-find-library-dir "org")
Or, in your case:
(concat (org-find-library-dir "org") "etc/R")
If you don't need to do this programmatically, you could use M-x describe-mode and in the description one of first lines is Org mode defined in org.el The link to org.el is clickable, and leads to org-mode's directory.
I found a solution which is efectively using locate-library and to truncate the not-needed elements (file name and last dir) and assembles them again as a path:
(locate-library "org")
"/Users/rainerkrug/.emacs.d/org-mode/lisp/org.elc"
(split-string (locate-library "org") "/")
("" "Users" "rainerkrug" ".emacs.d" "org-mode" "lisp" "org.elc")
(butlast (split-string (locate-library "org") "/") 2)
("" "Users" "rainerkrug" ".emacs.d" "org-mode")
(append (butlast (split-string (locate-library "org") "/") 2) '("etc" "R"))
("" "Users" "rainerkrug" ".emacs.d" "org-mode" "etc" "R")
(mapconcat 'identity
(append (butlast (split-string (locate-library "org") "/") 2) '("etc" "R"))
"/")
"/Users/rainerkrug/.emacs.d/org-mode/etc/R"
As pointed out in the comments, the usage of split-string is suboptimal. Please see accepted answer for the best approach.
I am looking to create a custom config for emacs to use for Erlang work and I want to refer to my custom EDTS repo as being under the directory from which init.el was loaded. Right now I have this:
(add-to-list 'load-path "~/.emacs-edts/edts/")
But I would rather not hardcode it and refer to it by variable.
Suggestions?
Strictly speaking the answer is (file-name-directory user-init-file), but instead see C-hv user-emacs-directory
I have the following snippet in my init.el:
(setq my-init-dir
(file-name-directory
(or load-file-name (buffer-file-name))))
This has the advantage of working whether init.el is in your emacs.d directory or not.
I have the following in my init file:
(defun my-file-name-basename (s)
"The directory name, without the final part.
For example:
(my-file-name-basename \"alpha/beta/gamma\") => \"alpha/beta\""
(substring (file-name-directory s) 0 -1))
;; Note: Normally, it's not possible to find out the file a specific
;; function is defined in. However, it's possible to save the file
;; name at the time this file was loaded.
(defvar my-load-file-name load-file-name
"The file name of this file.")
(defun my-start-directory (&optional path)
"The root directory that contains this module.
When PATH is specified, return the start directory concatenated with PATH.
Otherwise return the directory with a trailing slash."
;; Note: Try to figure out where we are, so that we can add the
;; subdirectories. `load-file-name' only works when the file is
;; loaded. Picking up the file from the symbol works when this is
;; evaluated later.
(let ((file-name (or my-load-file-name
(symbol-file 'my-start-directory)
;; Default value. (This is used, for example,
;; when using `eval-buffer' or `eval-region'.)
"~/emacs")))
(let ((start (concat (my-file-name-basename
(my-file-name-basename file-name))
"/")))
(if path
(concat start path)
start))))
In addition to finding out where the file containing the above above code is located (which does not have to be the init file), it provides a convenient way to create paths based on it. For example:
(setq custom-file (my-start-directory "init/custom.el"))
With these lines in my init.el I am able to sync the Emacs LaTeX buffer with Sumatra:
(setq TeX-source-correlate-mode t)
(setq TeX-source-correlate-method 'synctex)
(setq TeX-view-program-list
'(("Sumatra PDF" ("\"C:/bin86/SumatraPDF/SumatraPDF.exe\" -reuse-instance"
(mode-io-correlate " -forward-search %b %n ") " %o"))))
(setq TeX-view-program-selection
'(((output-dvi style-pstricks) "dvips and start") (output-dvi "Yap")
(output-pdf "Sumatra PDF") (output-html "start")))
To set a double click on the PDF to get me to the related LaTeX code, I also set in Sumatra options Set inverse search command line to:
"c:\bin86\GNU Emacs 24.2\bin\emacsclient.exe" --no-wait +%l "%f"
Despite the sync works, I’d like to code it differently.
If I didn’t set the last expression, (setq TeX-view-program-selection..., I would get the default values, which are the same as above, apart from the value for the PDF output that would be: (output-pdf "start").
I’d like to change this one to "Sumatra PDF" and leave the other values to their default, that is, I’d like to ask Emacs the default values for the viewers and change only the PDF value.
It is mostly an ELisp question concerning the manipulation of the variable TeX-view-program-selection.
Thanks for helping.
P.S. Please tell me if this question is best fit on tex.stackexchange
Update based on lunaryorn comments/answer
To update TeX-view-program-selection I could use:
(assq-delete-all 'output-pdf TeX-view-program-selection)
(add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF"))
The first line is optional, but it makes the list look "cleaner".
In both cases (with or without assq-delete-all) I now need to insert the code in the proper hook, since TeX-view-program-selection is void in init.el.
My credits to lunaryorn for suggestions! I am repackaging the steps involved to the benefits of the others.
Emacs side
Add to your init.el:
(setq TeX-PDF-mode t)
(setq TeX-source-correlate-mode t)
(setq TeX-source-correlate-method 'synctex)
(setq TeX-view-program-list
'(("Sumatra PDF" ("\"path/to/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"))))
Sumatra side
In Settings->Options dialog set Set inverse search command line to:
"path\to\GNU Emacs ver\bin\emacsclient.exe" --no-wait +%l "%f"
How to use
In your LaTeX document in Emacs type C-c C-v or double click the related PDF in Sumatra and ... enjoy))
Use add-to-list instead of setq. See C-h f add-to-list for more information.
TeX-view-program-selection is defined in tex.el, so you'll need to execute this code after this library is loaded:
(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"))))
I was driven nearly mad by the quoting conventions for windows ->emacs
If you install SumatraPDF in the default place, then this works on windows 8.1
(setq TeX-view-program-list
'(("Sumatra PDF" ("\"C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe\" -reuse-instance"
(mode-io-correlate " -forward-search %b %n ") " %o")))))
That's an hour or so I'll never get back :)
I have prepared a batch file, Emacs_SumatraPDF.bat.
It works perfect with sumatra-forward.el to realize forward and backward search.
For example:
Download
http://www.ai.soc.i.kyoto-u.ac.jp/~shi/files/Emacs_SumatraPDF.bat
http:/william.famille-blum.org/software/sumatra/sumatra-forward.el
Prepare
put Emacs_SumatraPDF.bat and SumatraPDF.exe -->
%Emacs_Home%/bin.
put sumatra-forward.el --> %Emacs_Home%/site-lisp
Usage
;Emacs_Home=C:/Program Files (x86)/GNU Emacs 23.4
;~\.emacs add following information
;;; Emacs_SumatraPDF.bat
;; #info: pdf viewer
; #refer:
(setq TeX-view-program-list '(
("Sumatra" "C:/Program Files (x86)/GNU Emacs 23.4/bin/Emacs_SumatraPDF.bat
%o %t %n") ))
(setq TeX-view-program-selection '(
(output-pdf "Sumatra")
(output-dvi "Yap")
((output-dvi style-pstricks) "dvips and start")
(output-html "start")))
;;; sumatra-forward.el
;; #info: forward search.
; #refer: http:/william.famille-blum.org/blog/static.php?page=static081010-000413
(require 'sumatra-forward)
That is all.
Besides
Emacs 4 Latex Support under Windows 7 for newcomer for Emacs.
http://chunqishi.github.io/emacs4ls/
It's worth mentioning that Set inverse search command line is invisible in the Settings->Options dialog by default. To show this option field, go to Settings->Advanced options or open SumatraPDF-settings.txt and turn on EnableTeXEnhancements = true.
EDIT: It turns out that the second edit to my .emacs file actually works. (See the comments below this entry.)
I tried a couple of addition to the .emacs to make all txt files opened in emacs use orgmode. They did not work. How can I make it happen?
;;SET EMACS AS DEFAULT MAJOR MODE TO FOR ALL FILES WITH AN UNSPECIFIED MODE
(setq default-major-mode 'org-mode)
;;OPEN ALL TXT FILES IN ORGMODE
(add-to-list 'auto-mode-alist '("\\.txt$" . org-mode))
Additionally:
It would be even better to open only txt files in a certain directory orgmode. Any hint as to how that could be done would also be appreciated.
Another way to do this is using directory-local variables. This is nice because you can put a file in any directory where you want this behavior to engage, and it works recursively in any subdirectories.
Create a file called .dir-locals.el in the desired directory.
Here are the contents:
((nil (eval . (if (string-match ".txt$" (buffer-file-name))(org-mode)))))
Read this like so: for any major-mode (nil), evaluate the following form:
(if .... (org-mode))
The regex in auto-mode-alist could be something more complex, like "^/path/to/.*\\.txt$"
You can implement a hook which verifies the file directory and modifies the buffer mode:
(add-hook 'find-file-hooks
(lambda ()
(let ((file (buffer-file-name)))
(when (and file (equal (file-name-directory file) "c:/temp/"))
(org-mode)))))
As an alternative you can add the mode line in the beginning of your text file. In this case emacs will set the specified mode.
; -*- mode: org;-*-
* header 1
** header 2
I glued together some code from Oleg Pavliv's answer here, and from yibe's at elisp - File extension hook in Emacs - Stack Overflow
(defun use-org-mode-for-dot-txt-files-in-owncloud ()
(when (and (string-match owncloud buffer-file-name)
(string-match "\\.txt\\'" buffer-file-name))
(org-mode)))
(add-hook 'find-file-hook 'use-org-mode-for-dot-txt-files-in-owncloud)
This way, though ownCloud Web and phone apps are currently friendly only with .txt files, from my PC I can use Emacs' Org-mode for them.
(If I set all .txt files to use Org-mode, it breaks todotxt-mode.)
(Note that owncloud is a string variable equal to my ownCloud path.)