[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] Custom source block for concept map markdown
From: |
Ben Feldman |
Subject: |
[O] Custom source block for concept map markdown |
Date: |
Fri, 1 Jul 2016 15:14:27 +0200 |
Hi,
my goal is to create a custom source block to create concept maps. The source
block contains
my custom made pseudo code. When exporting the org-file to LaTeX and PDF this
pseudo code
must be translated to DOT code. This DOT code is interpreted by the dot2texi
package.
The reason for the pseudo code is that it is more easy human readable. The
reason for dot2texi is
that vanilla DOT does not allow for labels on edges, i.e. labels that cross the
edge.
Here is an example of a concept map:
https://upload.wikimedia.org/wikipedia/commons/c/c3/Electricity_Concept_Map.gif
This is an example of my pseudo code for a single connection between two
concepts
and a label for that connection:
(Electricity) {is a form of} (Energy)
As you see it looks like a sentence.
The DOT code for this would look like this:
"Electricity" -> "Energy" [label="is a form of"];
Clearly, this doesn’t look like a proper sentence. Therefore I concocted the
following
function that takes a region containing my pseudo code and translates it to DOT
code:
(defun concept2dot (rStart rEnd)
(interactive "r")
(save-restriction
(narrow-to-region rStart rEnd)
(goto-char (point-min))
(while (re-search-forward "(\\([[:word:]].*\\)) +{\\([[:word:]].*\\)}
+(\\([[:word:]].*\\))" nil t)
(replace-match (concat "\"" (match-string 1) "\"" " -> " "\""
(match-string 3) "\"" " [label=\"" (match-string 2) "\"];") t nil))
)
)
After translating my pseudo code to DOT code a LaTeX source block with that DOT
code would look like this:
#+LATEX_HEADER: \usepackage{dot2texi}
#+LATEX_HEADER: \usepackage{tikz}
#+LATEX_HEADER: \usetikzlibrary{shapes, arrows}
#+BEGIN_LATEX
\begin{dot2tex}[tikz, tikzedgelabels, options={-t raw --nodeoptions='every
node/.style={text width=2cm, text centered, rounded corners, fill=black!10}'
--edgeoptions="every node/.style={fill=white, inner sep=1pt}"}]
digraph G {
node [shape=box, fixedsize=true, width=1.2];
"Electricity" -> "Energy" [label="is a form of"];
}
\end{dot2tex}
#+END_LATEX
However, I want to avoid firstly translating my pseudo code manually by
selecting a region and applying my function to it. Secondly, I want to
get rid of all the LaTeX code. Ideally the end result should look like this:
#+BEGIN_SRC conceptmap
(Electricity) {is a form of} (Energy)
(Energy) {that can exist in the form} (Lightning)
(Energy) {that can exist in the form of} (Thunder)
#+END_SRC
When I export my org-file to LaTeX the translation into DOT code occurs
automatically.
What would be the easiest way to achieve this result?
Thanks, B.F.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [O] Custom source block for concept map markdown,
Ben Feldman <=