emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Custom source block for concept map markdown
@ 2016-07-01 13:14 Ben Feldman
  0 siblings, 0 replies; only message in thread
From: Ben Feldman @ 2016-07-01 13:14 UTC (permalink / raw)
  To: emacs-orgmode

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-07-01 13:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-01 13:14 Custom source block for concept map markdown Ben Feldman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).