How can I use other heading styles like twiki ---+ or mediawiki == h2 == in org-mode? - emacs

I really want to use org-mode.
But, I want to use org-mode to understand structured documents that have already been written using different heading syntax,
e.g. using twiki's ---+
---+ H1
Top level
---++ H2
Nested
---+ H1 #2
Second top level
Or mediawiki like
= H1 =
Top level
== H2 ==
Nested
= H1 #2 =
Second top level
I'd like to have all of the goodness of org-mode folding, etc., just using these different heading styles.
Actually, worse that that:
I would like, say, the twiki or mediawaiki headings to take priority over org mode asterisk headings. But I would like to have both in use.
= H1 =
Top level
* this is a list
** nested
* list
** nested
== H2 ==
Nested
= H1 #2 =
Second top level
--+ What I have tried so far
I have been able to use outline mode to handle twiki,
for example via
---+ Emacs stuff
# try (defvar twiki-outline-regexp "---+\\++ \\|\\(\\(?: \\)+\\)[0-9*] ")
Local Variables: ***
outline-regexp: "^---\\++" ***
org-outline-regexp: "^---\\++" ***
End: ***
However, org-outline-regexp doesn't do hwat I would hope.
emacs' outline-mode's out-level function looks almost exactly like what I want.
(defvar outline-level 'outline-level
"*Function of no args to compute a header's nesting level in an outline.
It can assume point is at the beginning of a header line and that the match
data reflects the `outline-regexp'.")
i.e. instead of regexps, a generic function.
But I have not managed to make it work with org-mode. It looks like org-mode does not really use this, or, rather, has other stuff.
;; In Org buffers, the value of `outline-regexp' is that of
;; `org-outline-regexp'. The only function still directly relying on
;; `outline-regexp' is `org-overview' so that `org-cycle' can do its
;; job when `orgstruct-mode' is active.
(defvar org-outline-regexp "\\*+ "
"Regexp to match Org headlines.")
(defconst org-outline-regexp-bol "^\\*+ "
"Regexp to match Org headlines.
This is similar to `org-outline-regexp' but additionally makes
sure that we are at the beginning of the line.")
(defconst org-heading-regexp "^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$"
"Matches an headline, putting stars and text into groups.
Stars are put in group 1 and the trimmed body in group 2.")
Failing this, well, the main thing that I want from org-mode is links, Asking another question here
How can I "linkify" a non-org-mode buffer in emacs

My frustration was simply that org-mode has different rules for what constitutes a new outline section than outline-mode does. It requires a space after the asterisks, so it doesn't work on my extensive collection of notes, which forgo those spaces.
I resolved that by removing the trailing space in the not-well-documented org-outline-regexp variable, which is used to initialize the buffer-local variable outline-regexp, and that seems to be working for me. E.g. (set-variable 'org-outline-regexp "\\*+")
As to your actual question, my guess is that other regexp's and code would have to change to handle radically different stuff like twiki or mediawiki headings.

Related

LaTeX math mode ($...$) font color in org mode

I have just started using org-mode and it looks awesome. The only issue that I have so far is that when I write a text in mathmode ($...$) it appears in the standard-text font color.
So, I would like to make org-mode to identify the mathmode text and be able to present it in some other color. Note that I don't need to change the color of the actual equation, just the source text in org-mode.
Here is an example of how the text is currently presented
A paper by Rohnert, titled "Moving a disc between polygons" introduces
a structure using which one can generate a solution (path) for
a given query in $O(\log n) + k$ time.
and how I would like it to look
A paper by Rohnert, titled "Moving a disc between polygons" introduces
a structure using which one can generate a solution (path) for
a given query in $O(\log n) + k$ time.
(Note that I would prefer to display in some given color, e.g. red, and not bold face.)
In Emacs version 24.4 and later, this is controlled via the variable org-highlight-latex-and-related:
Non-nil means highlight LaTeX related syntax in the buffer. When non
nil, the value should be a list containing any of the following
symbols:
`latex' Highlight LaTeX snippets and environments.
`script' Highlight subscript and superscript.
`entities' Highlight entities.
So something like
(eval-after-load 'org
'(setf org-highlight-latex-and-related '(latex)))
in your init should help. Such code is formatted according to the face org-latex-and-related.
In earlier versions, the variable org-highlight-latex-fragments-and-specials, which is a simpler nil / non-nil variable:
(eval-after-load 'org
'(setf org-highlight-latex-fragments-and-specials t))
In this case, the face org-latex-and-export-specials is used.

Emacs org: Promote all headings of a subtree during export?

I use emacs org a lot to export parts of org documents to latex/pdf. I was wondering whether there is a way to promote all headings of the selected parts during the export process. For instance, suppose the file looks like this:
* Project 1
** Task 1 :export:
*** Introduction
Text text text.
*** Results
Text text text.
* Project 2
The emacs org export to latex would produce a tex file of the following structure:
\section{Project 1}
\subsection{Task 1}
\subsubsection{Introduction}
Text text text.
\subsubsection{Results}
Text text text.
But because there is not highest level in the part to be exported, it would make more sense to have the following structure:
\section{Task 1}
\subsection{Introduction}
Text text text.
\subsection{Results}
Text text text.
Or, even better:
\title{Task 1}
\maketitle
\section{Introduction}
Text text text.
\section{Results}
Text text text.
I was wondering whether anyone has an idea how to go about this? My lisp skills are unfortunately very rudimentary, seems like it should not be too hard.
Thanks!
Stephan
The first behavior you describe can be achieved by adding the following to your .emacs:
;; Define a function for turning a single subtree into a top-level tree
;; (:export: headings might be located at an arbitrary nesting level,
;; so a single call to "org-promote-subtree" is not enough):
(defun org-promote-to-top-level ()
"Promote a single subtree to top-level."
(let ((cur-level (org-current-level)))
(loop repeat (/ (- cur-level 1) (org-level-increment))
do (org-promote-subtree))))
;; Define a function that applies "org-promote-to-top-level"
;; to each :export: subtree:
(defun org-export-trees-to-top-level (backend)
"Promote all subtrees tagged :export: to top-level.
BACKEND is the export back-end being used, as a symbol."
(org-map-entries 'org-promote-to-top-level "+export"))
;; Make org-mode run "org-export-subtrees-to-top-level" as part of the export
;; process:
(add-hook 'org-export-before-parsing-hook 'org-export-trees-to-top-level)
Implementing the second behavior is a bit trickier but you can use theorg-export-trees-to-top-level function as a starting point if that's what you ultimately need. I'd like to point out, however, that this will not work for files with more than one :export: subtree (unless you also come up with a way to decide which headline would become the \title in these cases).
Sources:
Logic of org-promote-to-top-level based on source code of org-cycle-level command
Using the org-mode mapping API
Relevant information about export hooks

How to get literal forward slashes in org-mode?

In text, can I make org-mode ignore forward slashes somehow? Phonetics uses /s/ to denote a certain level of analysis.
I assume that you do not want the text to appear emphasized in the buffer, nor in the output. This is a slightly more complex answer which will achieve that result:
There is a variable defined by Org-mode called org-emphasis-alist which defines the different emphasis modes, what their plain-text syntaxes are, and how they are exported to HTML. You can achieve the result you want by changing the value of this variable before Org-mode has been loaded. That last part is critical so note it well—Org-mode reads the value of org-emphasis-alist when it is loaded and uses that value to generate a regular expression for highlighting ("font-lock") purposes.
Here are two routes to that:
Add the following lines to your .emacs file above the lines that load Org-mode:
(setq org-emphasis-alist
`(("*" bold "<b>" "</b>")
;; ("/" italic "<i>" "</i>")
("_" underline "<span style=\"text-decoration:underline;\">" "</span>")
("=" org-code "<code>" "</code>" verbatim)
("~" org-verbatim "<code>" "</code>" verbatim)
("+" ,(if (featurep 'xemacs) 'org-table '(:strike-through t))
"<del>" "</del>")))
(Notice the commented out line.)
Make the change through Emacs' customization facility:
M-x customize RET
In the search box enter Org Emphasis and click Search.
Click the down arrow next to Org Emphasis Alist to reveal its value.
Find and click the second DEL button—corresponding to the italic list item.
Click the Save for future sessions button at the top of the buffer.
You can use
#+OPTIONS: *:nil
to turn off text-emphasis (bold,italics,underline). This will however only work on export itself, the emphasis will still be visible.
See the manual for other export options.
If you like the standard emphasis functionality of the forward slashes in org-mode, you could also just define a new environment. I put something like the following in the preamble whenever I do phonetics/phonology typesetting:
\newcommand\uRep[1]{$/$\textipa{#1}$/$}

Org-mode & Latex export: Any way to put short & long names in sectioning commands? Workarounds?

In standard Latex, one can use something like...
\section[short head]{A longer and more meaningful heading version for the section}
...that gives both a long and short version of a section (or other sectioning command) Thus, allowing for both meaningful sectioning 'titles' and, also, reasonable-looking running heads, TOCs, beamer navigation, etc..
Is there any way to easily achieve this in org mode? (That is without hard coding the sectioning commands in LATEX snippets and, thus, defeating most of the flexibility of changing sectioning levels and repurposing content for beamer, book, and article classes that is my reason for wanting to try orgmode, in first place?)
I tried a "workaround" that did not work. I tried editing the possible latex export classes by adding another class to org-export-latex-classes. This new class changes sectioning commands from \section{%s} to \section%s(EDIT-Fixed typo in slashes). Then I tested using [short]{longer version} in orgmode sections of the file. It worked, except it acted as if the longer version section heading was just "{" and "longer version" was body text! What is up with that?
Since version 8.0 the "org-export-latex-classes" strategy won't work anymore.
Instead, and dare I say much more elegantly, you can set the ALT_TITLE property for the heading.
See http://orgmode.org/manual/Table-of-contents.html.
The following org code:
* The Long Title of Section 1
:PROPERTIES:
:ALT_TITLE: Section 1
:END:
Lorem ipsum.
** The Long Title of Subsection 1-1
:PROPERTIES:
:ALT_TITLE: Subsection 1-1
:END:
Dolor sit amet.
will export to LaTeX as:
[...]
\section[Section 1]{The Long Title of Section 1}
\label{sec-1}
Lorem ipsum.
\subsection[Subsection 1-1]{The Long Title of Subsection 1-1}
\label{sec-1-1}
Dolor sit amet.
You had the right idea with creating your own LaTeX class. The problem lies with the way the templates are filled by the default org-fill-template function. I'm not so great with Lisp, but this this hack will do the trick. Add the following to your .emacs file:
(defun my-section (level text)
(let* ((in "") (out "")
(short-title (if (string-match "\\[.*\\]" text)
(substring text (match-beginning 0)
(match-end 0))
nil)))
(if short-title (setq text (substring text (match-end 0) -1)))
(setq in (org-fill-template
"\\section%S{%s}"
(list (cons "S" (or short-title ""))
(cons "s" (or text ""))))
out (copy-sequence "\\end{section}"))
(cons text (list in out in out))))
(add-to-list 'org-export-latex-classes
'("test"
"\\documentclass{article}"
my-section))
This declares a new latex class by adding a "test" class to the org-export-latex-classes. Here we declare, instead of the normal \\section{%s} stuff a function that takes two parameters --- the current level and the headline text --- and returns a modified cons cell. Some details of this information can be found in org-latex-export.el.
Above the adding to the list is where we actually define the function. This is honestly a hacky version, and I pulled a lot from the org-beamer-sectioning function in org-beamer.el file. This function basically searches the headline for anything that is like a LaTeX short label (i.e. [....]) removes it from the headline and sticks it before the actual section label. Right now this hack will only generate \section statements, no matter how deep the level - if you want something more intelligent like \chapter or \subsection or even unnumbered items, you'll need to do some more Lisping; again, see org-beamer.el for some help.
This bit of org-mode code
#+latex_class: test
* [short 1] this is 1 star
test
** this is a 2 star
test
*** [short 3] this is a 3 star
test
**** what happens
exports to LaTeX as (only relevant sections shown here):
\section[short 1]{ this is 1 star}
\label{sec-1}
test
\section{ this is a 2 star }
\label{sec-1-1}
test
\section[short 3]{ this is a 3 star}
\label{sec-1-1-1}
test
\section{ what happens }
\label{sec-1-1-1-1}
\end{section}
\end{section}
\end{section}
\end{section}
Although it's not a straight org-mode solution, it seems to work and can be a starting point for you. One of these days I might try to write it up properly and get it folded into the org-mode distribution.
It is possible to use the following commands in latex to define the text that should appear in the header to replace section names. But the TOC will still contain the original names.
\chaptermarks
\sectionmarks
\subsectionmarks
...
So, in org-mode you can write
* Long section title
#+LaTeX: \sectionmark{Short title}
edit: it actually doesn't work on the very page where the section name appears. On this one only, the full name is still put in the header.

How to make part of a word bold in org-mode

How can I make org-mode markup work for a part of a word? For example, I'd like it to work for cases like this:
=Class=es
and this:
/Method/s
Based on my tests it seems like org-mode markup syntax works on complete words only.
These days, there is a way to do this (without using quoted HTML tags):
(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)
Explanation
The manual says that org-emphasis-regexp-components can be used to
fine tune what characters are allowed before and after the markup characters [...].
It is a list containing five entries. The first entry lists characters that are allowed to immediately precede markup characters, and the second entry lists characters that are allowed to follow markup characters. By default, letters are not included in either one of these entries. So in order to successfully apply formatting to strings immediately preceded or followed by a letter, we have to add [:alpha:] (which matches any letter) to both entries.
This is what the calls to setcar do. The purpose of the third line is to rebuild the regular expression for emphasis based on the modified version of org-emphasis-regexp-components.
I don't think you can do it so that it shows up in the buffer as bold. If you just need it so that it appears bold when you export it to html, you can use:
th#<b>is is ha#</b>lf bold
See Quoting HTML tags
No, you can't do that. I searched for the same solution before and found nothing. A (very) bad hack is to do something like *Class* es (with a whitespace).
Perhaps you can write a short message to the creator, Carsten Dominik (Homepage), and ask him for a solution. He seems to be a nice guy.
A solution that has not been mentioned is to use a unicode zero width space (U+200B) in between the desired bolded and unbolded parts of a word.
To get the desired bolding of the word "Classes":
Type 'Class*es' in the buffer (without quotes).
Move the cursor between the '*' and 'e' characters.
Press C-x 8 RET (to execute the insert-char command).
Type 'zero width space' (without quotes) and press RET.
Move the cursor to the beginning of the word and insert a '*' character.
The word "Classes" should now have the desired appearance.
Note that there is the possibility that this will cause problems when exporting.
src_latex{\textbf{Class}es and \textit{Method}s}
Building up on the previous excellent answer
I had to modify it a bit in order to make it work with spacemacs. Indeed, from the spacamacs org-layer documentation, available here, we can read
Because of autoloading, calling to org functions will trigger the
loading up of the org shipped with emacs which will induce conflicts.
One way to avoid conflict is to wrap your org config code in a
with-eval-after-load block [...]
So, I put the following lines inside my dotspacemacs/user-config ()
(eval-after-load "org"
'(progn
(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)
))