I'm wondering I if there's any functionality in org-mode that can make me able to operate with secret structure, that is: structure that I can see when I'm editing but that is treated as if it wasn't there when exporting. It's mainly importing when I export to ascii.
Example:
I would like this in the .org file:
* Normal heading
** Secret heading 1
Some text 1
** Secret heading 2
Some text 2
** Secret heading 3
Some text 3
To be exported to this:
Normal heading
--------------
Some text 1
Some text 2
Some text 3
What makes the headings secret can be anything like a tag, a property or something else but the secret headings should be foldable.
Edit:
Found this solution (from here) (I'm using org-mode 7.9.3 f. It doesn't work. Headlines with the :ignoreheading: tag are still displayed:
;; backend aware export preprocess hook
(defun sa-org-export-preprocess-hook ()
"My backend aware export preprocess hook."
(save-excursion
(when (eq org-export-current-backend 'latex)
;; ignoreheading tag for bibliographies and appendices
(let* ((tag "ignoreheading"))
(org-map-entries (lambda ()
(delete-region (point-at-bol) (point-at-eol)))
(concat ":" tag ":"))))))
(add-hook 'org-export-preprocess-hook 'sa-org-export-preprocess-hook)
You can use the EXCLUDE_TAGS property and tag certain sections, then export with org-export-exclude-tags. E.g:
#+EXCLUDE_TAGS: noexport
* Public Section
* Secret Section :noexport:
Documentation here.
What you want is addressed here -- and here's the answer (repeated):
Add the following to your .emacs file:
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines))
Use the ignore tag on headlines you'd like to have ignored (while not ignoring their content)
I upgraded to org-mode 8.2.5h and with that this works:
(defun sa-ignore-headline (contents backend info)
"Ignore headlines with tag `ignoreheading'."
(when (and (org-export-derived-backend-p backend 'latex 'html 'ascii)
(string-match "\\`.*ignoreheading.*\n"
(downcase contents)))
(replace-match "" nil nil contents)))
(add-to-list 'org-export-filter-headline-functions 'sa-ignore-headline)
But only if you don't have the options: #+OPTIONS: tags:nil. Guess it's sort of obvious that tags shouldn't be filtered away before a filtering that relies on a certain tag is invoked - but that bugged me for quite some time.
Note: when exporting to ascii the headline underlining will remain without the headline, so you need this setting too:
(setq org-ascii-underline (quote ((ascii) (latin1) (utf-8))))
... to remove headlines all together.
In the linked question about the ignoreheading tag I posted a working, simpler org-export-before-parsing-hook solution for Org 8.2.10 in Emacs 24.1.1.
It is based on the documentation of the org-map-entries function which also states that it wraps it in save-recursion automatically. It is simpler than using concat because the second argument to org-map-entries is an agenda-style match string.
While trying to solve the same problem I found this thread describing how to extend ox-extra.el using a notignore tag. This method does not export any headings unless explicitly tagged notignore. Content of the heading are exported normally.
For most of my documents the notignore approach is more useful than the 'ignore' approach because the majority of headings are 'secret structure' not intended for export.
Presently I have notignore-headlines activated in my init.el file. Can anyone suggest a way to activate this on a per document basis.
Related
I would like to setup a personal wiki in org-mode.
So far, I have tried this two ways. My first attempt was using a single "Scientific Notebook.org" file. In this went all my notes - each with its own headline, date and tags (same format as a blog post). I then turned on org-velocity to quickly navigate the file.
But this created two problems: first, I use a lot of math in my notes (LaTeX previews are one of the reasons I want to us org). But these take sooooo long to load, I can't images trying to open a file with several thousand entries (all filled with math!!)
The other problem I have is with tags. I like to use a lot of multi-word tags to cross-reference my notes. But the way org-mode wraps these in the buffer, makes my headings completely unintelligible. Also (maybe it's just me but) I find CamelCase really hard to read, especially when faced with something like:
:monotonicTransformations:homogeneousFunctions:orderedSets:proofs:
Now my second attempt is with Deft. Here, I have broken up each note into its own .org file and creating a dedicated ~/org/ folder to hold my wiki. But this is where I am stuck:
1) How do you setup auto linking, so that typing say "foo bar" in one note, creates a link to "foo bar.org"? Can this be done with radio target? If not, can this syntax [[foo bar]] be overridden to search for headlines in all files in the ~/org/ directory? I tried adding Wiki.el as a minor mode but no dice...
2) How do you tag individual files? And how can you then pull up a list of all tags and use this to filter your list of notes? I have read that bookmark+ lets you do file tagging. But I got so lost in the online docs...
I would love to hear how others have solved these problem, what minor modes you are using, workflows and keyboard shortcuts or other mods!
Thanks!
-Adam
I'm using a simplistic code for a wiki.
Because that's what a wiki is for me: a quick way to categorize things.
The structure is a following:
each subject has its own org file
each topic of subject has its own heading
all org files are in single directory
you can jump to file, or create a new file with helm
That's it. I've found to need to link anything to anything, jump-to-subject functionality
is more than enough. Here's how this looks:
And once within a subject, I can jump across topics with worf.
Here's how this looks:
Having only one note file is, in my opinion, more flexible and compatible. It tends, however, to get slow for even moderatly sized files. Multiple small files are quick, but they need more effort to set up, and they only work within that setup.
Single File Solution
To speed things up, consider setting org-startup-with-latex-preview to nil (or add #+STARTUP: nolatexpreview to your file).
Tags not only get messy when used for keywords, using them also gets rather slow as your file grows. I've played around with some custom functions, but now avoid tags most of the time. Instead I use flat hierarchies, categories and otherwise rely on occur and org-occur (e.g. M-x org-occur begin_proof).
Multiple Files
The org syntax for linking to other files is rather simple: [[./this idea.org][this idea]]. If that is too much hassle, it should be easy to write a function that replaces the active region with an appropriate link.
If you want to link [[this idea]] to a file "this idea.org", you could add a function to org-open-at-point-functions and handle it yourself.
As for tags, you don't tag a file itself, but rather a single top level headline. This of course means that all your troubles with tags a back as well.
Again, I would recommend not using tags. Just make sure the file contains the right keywords at the right places and use occur and friends.
Edit: An Example `org-open-at-point-function'
If you want to search for a fuzzy link in all files in a directory instead of only the current buffer, you can do this by using the org-open-at-point-functions hook. Here is an example:
(defvar my-link-search-directory "/my/notes/directory/")
(defun my-open-link-function ()
"Open link, interpreting it a the name of a headline."
(let* ((el (org-element-context))
(type (first el))
(link-type (plist-get (cadr el) :type))
(path (let ((path-1 (plist-get (cadr el) :path)))
(when (stringp path-1)
(org-link-unescape path-1)))))
(when (and (eql type 'link)
path
(string= link-type "fuzzy"))
(let* ((path (regexp-quote path))
(result
(delq nil
(org-map-entries
(lambda ()
(when (string-match
path
(org-get-heading))
(list (buffer-file-name) (point))))
nil
;; Here we set the scope.
;; 'agenda would search in all agenda files.
;; We want a list of all org files in `my-link-search-directory'.
(directory-files
my-link-search-directory
t "[.]org\\'")))))
(when result
(when (> (length result) 1)
(message "Warning: multiple search results for %s" path))
(let ((file (caar result))
(pos (cadar result)))
(find-file file)
(goto-char pos)))))))
(add-hook
'org-open-at-point-functions
'my-open-link-function)
Note that I haven't tested this much.
Actually, I would recommend against using this unless you really need it. While making fancy extensions is tempting, keeping your notes as simple as possible is preferably. If you have everything in one file, you could edit your notes with notepad or google docs or whatever, should you ever need to.
I'm using org-mode to write a report which I then export to LaTeX.
I have a few different .org files (one per chapter), which I export as "headless" LaTeX and then combine in a master .tex file.
This works nicely, except that the generated .tex files contain labels with conflicting numbers. So both a.tex and b.tex contain \label{sec-1}, for example.
As long as I never actually use these references then it's not much of a problem I think, although the warnings do annoy me. Is there any way to turn off the generation of these labels? It should be simple but I cannot find anything about this in the documentation.
I have written a bit of Lisp which will remove said labels after the export to LaTeX, which looks like this:
(defun remove-orgmode-latex-labels ()
"Remove labels generated by org-mode"
(interactive)
(let ((case-fold-search nil))
(goto-char 1)
(replace-regexp "\\\\label{sec-[0-9][^}]*}" "")
)
)
(add-hook 'org-export-latex-final-hook 'remove-orgmode-latex-labels)
This seems to do the job without removing my own custom labels.
Why not writing your full report as one big Org file?
Anyway, if your prefer having multiple smaller files, I would advice "including" them in one Org master file, as this:
* Chapter 1
#+INCLUDE: "chapter1.org"
* Chapter 2
#+INCLUDE: "chapter2.org"
That way, Org sees only one file (then, I guess that your problem simply disappears), while you edit them as you wish.
As of now (18. 05. 2021) correct solution is this:
(defun my-latex-filter-removeOrgAutoLabels (text backend info)
"Org-mode automatically generates labels for headings despite explicit use of `#+LABEL`. This filter forcibly removes all automatically generated org-labels in headings."
(when (org-export-derived-backend-p backend 'latex)
(replace-regexp-in-string "\\\\label{sec:org[a-f0-9]+}\n" "" text)))
(add-to-list 'org-export-filter-headline-functions
'my-latex-filter-removeOrgAutoLabels)
Only slight modification of previous answer.
This is what worked for me with recent (2020) Org-Mode:
(defun rm-org-latex-labels (text backend _info)
"Remove labels auto-generated by `org-mode' export to LaTeX."
(when (eq backend 'latex)
(replace-regexp-in-string "\\\\label{sec:org[a-f0-9]+}\n" "" text)))
(add-to-list #'org-export-filter-headline-functions
#'rm-org-latex-labels)
When using Org-mode and its LaTeX export BibTeX or Biblatex is often used to handle references. In that case the LaTeX command \printbibliography is often included in the org file. \printbibliography is placed in the org file where LaTeX is supposed to write out the reference list. What \printbibliography does is to insert a LaTeX header along with the reference list. In most cases \printbibliography is placed at the end of the org file simply because in most documents the reference list is to be placed last. This means that \printbibliography will be included under the last heading in the org file, e.g.
* Heading
\printbibliography
It also means that when that heading is folded the \printbibliography will be swallowed:
* Heading...
But this goes against the meaning of \printbibliography because it includes its own heading in the output. Also, it will be confusing when \printbibliography is swallowed and a new heading is placed after it because then the reference list will no longer appear last in the document.
How can I make it so that \printbibliography is not swallowed by sections in Org-mode? A bonus question: how can I make it so that Org-mode does not create headings after \printbibliography unless C-Ret is pressed when the cursor is after it?
In searching for a solution to this problem I found http://comments.gmane.org/gmane.emacs.orgmode/49545.
A workaround for this problem is to make \printbibliography not return a LaTeX heading so that it can appropriately be placed under an Org-mode heading.
With biblatex this can be done by supplying \printbibliography with the option heading=none and placing it under an appropriate heading. Here is an example:
* Heading
* References
\printbibliography[heading=none]
This way references can be kept in a heading of its own and \printbibliography being swallowed by a heading is not a problem because it is being swallowed by its own heading.
The following is lightly tested but works for me using tab and shift-tab to hide and display things. Those are the only hiding and showing commands that I use, so if you use other commands they may have to be advised or fixed in some other way.
You can of course change org-footer-regexp to anything you want. I was hoping to not have to use any advice, but without advising org-end-of-subtree the last heading never cycles with tab because it thinks it's not hidden, so it hides it and then org-cycle-hook unhides it. It calls org-end-of-subtree before running org-pre-cycle-hook so that's not an option either.
(defvar org-footer-regexp "^\\\\printbibliography\\[.*\\]$"
"Regexp to match the whole line of the first line of the footer which should always be shown.")
(defun show-org-footer (&rest ignore)
(save-excursion
(goto-char (point-max))
(when (re-search-backward org-footer-regexp nil t)
(outline-flag-region (1- (point)) (point-max) nil))))
(add-hook 'org-cycle-hook 'show-org-footer)
(add-hook 'org-occur-hook 'show-org-footer)
(defadvice org-end-of-subtree (after always-show-org-footer
()
activate)
(when (>= (point) (1- (point-max)))
(re-search-backward org-footer-regexp nil t)
(setq ad-return-value (point))))
One solution would be the following:
#+macro: printbiblio (add extra spaces here, but cannot add comment)
* Test 2
This is a test
* {{{printbiblio}}}
Test text
\printbibliography
*
asdf
Like this you end up with a blank heading at the bottom of the document. The macro expands to a blank block of text so you end up with
\section{Test 2}
\label{sec-1}
This is a test
\section{}
Test text
\printbibliography
\section{}
asdf
This also ensures you cannot accidentally add headlines after your bibliography, since it is it's own (empty) headline. It might be (seems to be actually) included in the table of contents, which is unfortunate but I would suspect the solution would be at worst run a post-export to remove the empty headline from the file (or manually do so before converting to PDF).
Another solution would be to put the bibliography under a heading named "References" like so:
* Heading
Some text
* References
\printbibliography
and remove the \section{References} from the resulting latex file by adding this to your emacs init file
(defun org-export-latex-remove-references-heading (contents backend info)
(if (not (eq backend 'latex))
contents
(replace-regexp-in-string "\\\\section\\*?{References}\\s-*\\\\label{.*?}" "" contents)
))
(add-hook 'org-export-filter-final-output-functions 'org-export-latex-remove-references-heading)
Note that this assumes you only have one heading that's named "References", as it replaces all occurrences of it. It also assumes the sections are in this format:
\section{References}
\label{<any_string>}
\printbibliography
For other formats you need to change the regular expression in the org-export-latex-remove-references-heading function.
* References
:PROPERTIES:
:UNNUMBERED: t
:END:
\printbibliography[heading=none]
There is an easier way to solve this.
Just add an "unnumbered" properties to the heading and it will be exported without any numbering.
I'm trying to get create a capture template that converts an URL to an org-mode link with the <title> as the link name.
My conversion function looks like this:
(defun get-page-title (url)
"Get title of web page, whose url can be found in the current line"
;; Get title of web page, with the help of functions in url.el
(with-current-buffer (url-retrieve-synchronously url)
;; find title by grep the html code
(goto-char 0)
(re-search-forward "<title>\\([^<]*\\)</title>" nil t 1)
(setq web_title_str (match-string 1))
;; find charset by grep the html code
(goto-char 0)
;; find the charset, assume utf-8 otherwise
(if (re-search-forward "charset=\\([-0-9a-zA-Z]*\\)" nil t 1)
(setq coding_charset (downcase (match-string 1)))
(setq coding_charset "utf-8")
;; decode the string of title.
(setq web_title_str (decode-coding-string web_title_str (intern
coding_charset)))
)
(concat "[[" url "][" web_title_str "]]")
))
When called from normal emacs lisp code it returns the correct result. But when used in this org-capture-template it only returns bad url.
setq org-capture-templates
(quote
(("l" "Link" entry (file+headline "" "Links")
"* \"%c\" %(get-page-title \"%c\")"))))
Is the order of expansion different? Do I need to escape the string differently? Magic?
The first %c is only their to debug the string and indeed is getting printed as "url".
Please don't even bother pointing out that parsing XML with regexp is the wrong approach. Cthulhu is already haunting me and this isn't going to make it worse.
The problem is the order of expansion of template parameters. The simple % templates are expanded after the sexp has been evaluated. The original error message still contains a template and thus is expanded into the contents of the clipboard and thus the error message contains not the string that was originally passed to get-page-title.
The solution is to access the kill ring from within the sexp:
%(get-page-title (current-kill 0))
EDIT This behavior is now documented in org-mode.
Wouldn't the solution be to use org-protocol.el?
http://orgmode.org/worg/org-contrib/org-protocol.html
I just tested it with the following template (adding a sub-heading for your desired title as headline).
Template:
("t"
"Testing Template"
entry
(file+headline "~/org/capture.org" "Testing")
"* %^{Title}\n** %:description\n\n Source: %u, %c\n\n%i"
:empty-lines 1)
Then using a browser-based keybind (in my case with Opera, although examples for Firefox, Uzbl, Acrobat and Conkeror are provided as well) I was able to capture the following:
** Testing for StackExchange
*** org-protocol.el - Intercept calls from emacsclient to trigger custom actions
Source: [2011-08-05 Fri], [[http://orgmode.org/worg/org-contrib/org-protocol.html]
[org-protocol.el - Intercept calls from emacsclient to trigger custom actions]]
org-protocol intercepts calls from emacsclient to trigger custom actions
without external dependencies.
(I broke the org-link simply to keep the scrolling to a minimum, it was not on two lines originally)
#aboabo shared an undocumented variable in https://stackoverflow.com/a/21080770/255961 that provides a more general solution to the question's topic of how to use sexp with keyword values in a template (beyond kill ring). The variable org-store-link-plist stores all the information being passed to the capture. So you can access its values directly from a function like this:
(defun url()
(plist-get org-store-link-plist :url))
("w" "capture" entry (file "~/refile.org")
"* [[%:link][%:description]] :NOTE:\n%(url)%U\n"
:immediate-finish t)
PS, According to the manual page (quote below) it sounds to me like your approach in teh question should work also. But I agree what you describe is what seems to be actually happening - it seems like a bug relative to the manual.
%(sexp) Evaluate Elisp sexp and replace with the result. For convenience,
%:keyword (see below) placeholders within the expression will be
expanded prior to this.
BACKGROUND: In org-mode, the variable org-archive-location is set to "%s_archive::" by default, so that a file "toto.org" archives into a file "toto.org_archive". I would like it to archive to "toto.ref" instead. I am using org-mode version 7.4 (out of the git server).
I would have thought it to be as simple as
(setq org-archive-location
`(replace-regexp-in-string ".org" ".ref" %s)
)
But I was pointed out that this was not proper in LISP (plus, it did not work). My final solution is as follow, you should be able to adapt to most clever configurations of org-archive-location:
(setq org-archive-location "%s::* ARCHIVES")
(defadvice org-extract-archive-file (after org-to-ref activate)
(setq ad-return-value
(replace-regexp-in-string "\\.org" ".ref" ad-return-value)
)
)
Note that:
1) I voluntarily did not add a $ at the end of ".org" so that it would properly alter "test.org.gpg" into "test.ref.gpg".
2) It seems that one should use the regular expression "\.org" (rather than, say, ".org") (longer explanation below in the answers).
You can't define a variable in Emacs such that its value is obtained by running code; variables have simple, static values.
You can achieve the effect you described by advising the function org-extract-archive-file, which is the one that generates an archive location from org-archive-location:
(defadvice org-extract-archive-file (after org-to-ref activate)
(setq ad-return-value
(replace-regexp-in-string "\\.org" ".ref" ad-return-value)))
This works for me now, but of course the internals of org-mode are subject to change and this solution may not work forever.
You should not quote an expression that you want to evaluate. Note also that in a regular expression, . matches any character.
Here is an example of how to set the file, the location (e.g., main heading) in the file, and whether or not to include additional archive information:
(let* (
(org-archive-location "~/todo.org::* TASKS")
(org-archive-save-context-info nil))
...)
You can try this: #+ARCHIVE: %s.ref:: at the beginning of your org file.
Read more about it here.
Also, other interesting option is to set inside your headtree the following, for instance:
* Main Header of tree
:PROPERTIES:
:ARCHIVE: toto.ref:: * Main Header of tree in archive file
:END:
** sub tree of main header and so on
The latter I took from this video.