Export to latex
Not logged in

Here is the lowest level function for transforming an outline into a latex nested list. It takes a tree from an outline as input and returns latext text as output.

 proc ::treeToLatex {tree} {
    lappend latex {\documentclass{book}} {\pagestyle{empty}  % suppress page numbers} {\begin{document}}
    $tree walk $tree rootname -order both {a n} {
        switch $a {
            enter {
                if {$tree depth $n != 0} {
                    if {($tree index $n == 0) && !$tree keyexists $n nobullet} {
                        lappend latex {\begin{enumerate}}
                    }
                    if {!$tree keyexists $n nobullet} {
                        set item {\item }
                        } else {
                        set item \n
                        }
                    lappend latex $item$tree set $n title
                    }
                }
            leave {
                if {$tree depth $n != 0} {
                    if {($tree index $n + 1 == $tree numchildren [$tree parent $n]) && !$tree keyexists $n nobullet} {
                        lappend latex {\end{enumerate}}
                        }
                    }
                }
            }
        }
    lappend latex {\end{document}}
    return join $latex \n
    }

Note that this makes use of an undocumented feature in tkoutline where bullets can be supressed (control-b). It treats those nodes with suppressed bullets as "body text" for the latex output.

This code (and more code that actually hooks this into a menu pick and writes to a file) will likely be included in a future release of tkoutline (not there as of 0.93). Until then, you can put the above code in your startup script and then while editing the outline you want to export, open the console (<F2>) and type the following:

 treeToLatex treecmd

Example outline (control-b has been hit for items without a bullet):

 [bad-link: -]- Appetizer
    [bad-link: -]- Salad
        [bad-link: -]- house
            [bad-link: -]- dressing
                Discussion of the various merits of salad dressing
  • Caesar
  • Soup
  • Main Course
  • Dessert Clearly chocolate is superior to vanilla

Output:

 \documentclass{book}
 \pagestyle{empty}  % suppress page numbers
 \begin{document}
 \begin{enumerate}
 \item Appetizer
 \begin{enumerate}
 \item Salad
 \begin{enumerate}
 \item house
 \begin{enumerate}
 \item dressing

Discussion of the various merits of salad dressing \item Caesar \end{enumerate} \end{enumerate} \item Soup \end{enumerate} \item Main Course \item Dessert

Clearly chocolate is superior to vanilla \end{enumerate} \end{document}


More design thoughts from rob mcdonald as posted to the mailing list:

Any tkoutline node can be flagged with a LaTeX attribute, but flagging is optional. The latex attribute may have one of the following values.

 part
 chapter
 section
 subsection
 subsubsection
 paragraph
 subparagraph
 text
 enumerate
 itemize

Right now, making an entry bullet-less with ^B is equivalent to marking it as text. This convention could be continued, or text could become an explicit attribute.

Once a node is labeled with an attribute, the hierarchy of subsequent nodes is implied according to a precedence order. The status of a buried node may be overridden by labeling it with an alternate attribute. This is a pretty simple approach that should work well. With a few exceptions...

enumerate and itemize may be nested under each other, and under the document structure labels (\section etc.) However, document structure labels may not appear under enumerate and itemize. enumerate and itemize are output just like the script you've already put together.

enumerate and itemize are limited to 4 levels of nesting. If you nest itemize at the deepest level of enumerate, you get 8 levels. If you do three levels of enumerate, followed by two levels of itemize, and then switch back to enumerate, you only get one level before it complains. It picks up where it left off. I.E. latex does not reset the enumerate (itemize) depth counter when you nest it within itemize (enumerate). I hope this makes sense...

text does not impact the hierarchy. A node may be flagged as text at any level, and if the following node is not text, its position in the hierarchy is not impacted by the text node.

text may appear at any level. text is output to the file by surrounding it with blank lines.

chapter does not exist for all latex document types. If you were to identify the document type to tkoutline, then it could be smart enough to know what levels exist. This complication is probably best left up to the user for now.

A default level for the top of tree needs to be chosen. section or enumerate seem to be the universally compatible choices.


and more

I've thought about it a little more, and a little complication sets in...

Lets say that you're at a node which is on level 4, and you assign an attribute of subsection. Everything below that node needs to have its attribute implied by the node you set. You continue traversing the tree, and come to a node on level 3, one that is no longer a child of the flagged node. You need to 'forget' the attribute override.

And to further complicate things, as you traverse a tree, you could pass two overriding attributes. In order to write out the latex file correctly, without having to re-traverse the tree to find out your latex level every time, I think we need to keep a stack (filo) of the overrides that are 'active' at the current place in the tree. Each override contains the level in the tree that it occured at, and the attribute setting that was overridden... So, the stack may look something like this...

 0 chapter                 ---  first in  (top)
 3 subsection
 5 enumerate             ---  last in  (bottom)

So, when you traverse the tree, the algorithm is something like this...

You first check to see if you've come back to the level of the last override on the stack. (You're on your way back up) If you have, you drop the bottom entry off the stack.

Then, you check to see if the current node has an attribute set. If it does, you add it to the bottom of the stack.

Next, you write out your current node according to its level relative to the bottom of the stack. (i.e. if you're on level 5, and the bottom override is a 3 subsection, then you write this out according to 5-3=2 i.e. subsection + 2 = paragraph)