Tinderbox and LaTeX

Interesting, but the core use case is someone writing in normal (‘rich’) styled text and Tinderbox inserting LaTeX macros for bold/italics, etc. So are Markdown-like things an advantage— unless one knows these already, else there are now two things to learn in order to get TeX text.

It certainly might be useful to make up a general rubric to Tinderbox+Org mode for TeX, though it would service a different use case to the one at hand. The disadvantaged group we are trying to assist are those with no or little LaTeX expertise who are being required to submit copy/manuscript to a LaTeX process. IOW, write ‘normally’ in Tinderbox but emit TeX (or copy it from the Text:export pane.

Thanks, Mark. Sorry, I wasn’t clear. Mapping Tinderbox rich styled text, including heading/outline structure, to LaTeX seems like a straightforward starting point for requirements in what to do. I wasn’t suggested that Markdown or Org markup be any part of that (although, obviously, handling Markdown that’s already in your Tinderbox notes would make sense, and also seems straightforward.

I’m suggesting that the facilities that Org provides for LaTex are examples of what seems to matter to a large number of people using it for writing documents that get turned into PDFs by LaTeX. So it’s a good place to see what things might be on the todo list. They don’t need to use Org syntax, or duplicate it. But if Tinderbox had roughly equivalent functionality for LaTeX export, in a Tinderbox-like way, that might be sufficient.

And if this isn’t helpful, ignore it! :slightly_smiling_face:

3 Likes

Not at all! Far from it, as I’m sure there will we others who may be doing similar to you. So it’s al useful. The fun is figuring out where/how to document it for them.

Thanks

Chiming in to say I use LaTeX regularly for all sorts of writing, from manuscripts to recommendation letters, making assignments, and sometimes for slides. I either write it directly (in TeXShop or emacs or VS Code), or export from org-mode, or from rmarkdown/quarto. MacTeX is very easy to install, although it is many GB large. Would love for LaTeX export to be smoother for TBX. Would increase its use for me for scholarly writing. I agree pandoc is also a good path (html or md to TeX for example), but also having TBX export settings that understand what html can do vs what TeX can do would be helpful.

Maybe also helpful to note: The way quarto/Rmd handle the fact that LaTeX can do much more than md is that you can include raw TeX in with the md and then the md goes to TeX via pandoc and the LaTeX is just passed through. Maybe TBX could do the same – handling just some basic set of common syntax by default and then if people want to be fancy they could add TeX in directly to notes.

That was the approach I used in my demo TBX above; for instance, using \footnote{} to demonstrate insertion of a LaTeX footnote. The same approach has long been used in Tinderbox by those writing for primary use in HTML by adding inline HTML that cannot be auto-inserted via the export process.

Attribute settings can be set dynamically. In my quick demo, I used a prototype to change HTML Export group values from HTML code to LaTeX code. I could as easily used action code or simply set the doc level defaults to LaTeX values. Thus perhaps the point for consideration here is are there any commonly used/needed LaTeX macros that occur in $Text that aren’t handled by (re-valuing) HTML export attributes.

One aspect of LaTeX writing not covered is citation anchor (\cite{}) insertion and attendant citekey lookup. Most TeX writing environments will—if the document asserts a bib file (or has inline BibTeX)—allow auto-listing/auto-complete of the BIB file’s contents. This may be done via Reference Managers (but not all people have/use those) but inclusion of a note holding BibTeX data might allow this:

The above is from Overleaf, but only as I have a doc open as I write, but my main LaTeX writing app ‘texstudio’ (https://texstudio.org) does the same and I’m sure others such do also. The numeric citekeys above are less helpful as an illustration than something like bernstein:2025:infocity , but the citekeys shown are just what are in the document at hand!

But as much LaTeX writing is probably academic or research and so citation are likely, dealing with this issue add time of writing seems useful, though how many might use these (i.e. ROI) I can’t guess.

Thanks @mwra – the intersection of inline citations with the Zotero/BibTeX features currently being added (and existing Bookends integration) would be quite interesting.

My thought was largely in line with yours (using existing export machinery), but maybe the activation energy could be lowered just a tad with something like a document-level preference to export to TeX instead of html, and then the various export group values could be changed automagically. People who want to use TeX for writing likely already have TeX installed, so Tinderbox’s job would just be to produce the .tex file, not to render it or handle all of the extra things associated with that.

1 Like

FWIW, a quasi-doc level preference can be achieved now, by adding a built-in (‘LaTeX’) prototype and two built-in templates (‘LaTeX document’ and ‘LaTeX’ text). That only requires adding the source data for those ‘notes’ into the app and adding a few menu items. Either the prototype or the template can set attributes like the export file extension and other non-HTML specific export features.

Having taken a deep dive into citation methods and formats it turns out there are not real unifying standards beyond the notion of a citation anchor and a style-text reference to which the former may have an N-to-1 links. Citation practice is mired in the Printocene era and digitally native text has to bend to practices born in a different era of text use. Those who say “there is no problem” turn out generally work in a closed/limited domain so simply never face formatting choices and thus assume standards where none exist.

What, in a post paper era, does ‘print to’ mean? If I export 10 notes in, for instance, as (La)TeX do I want 10 files that are complete TeX documents? Likely no. Indeed, better to copy paste per note TeX into the eventual TeX writing/production tool.

LaTeX is interesting too in a context of citation, as in-$Text citations need to be \cite{citekey} slugs not author-year or such, and the the reference list is needed ideally as a single BibTeX (TeX format) text. For number-based citation, as is common in the Sciences, the number of a given citation can only be assessed/inserted through multiple iterations of the source (find all cites, gather used references, sort into [publisher-style-assigned] order, then use reference sequence number to replace the in-$Text stub. That might be a bit much for Tinderbox to have to manage, but if LaTeX is the target output then a ‘scan’ then cite insertions need to be \cite{citekey} and not [Author Year, UI]. Of course that isn’t useful for non-LateX use.

Footnote-based citations, i.e. where all citations are made as foot-/chapter-/end-notes, are potentially problematic if the narrative uses multiple Tinderbox notes as where to the footnotes go? I each note, in a separate note and if so are thy sorted or simply appended. The latter matters as few people tend to care about the fit/finish of reference info as long as the editors or peer reviewers don’t complain. Of course as consumers of references were care rather more about clarity /correctness. The general vibe is everyone hoping ‘someone else’ is doing the heavy lift but that id rarely the case.

So my 2¢ suggestion here is the prototype+template based approach stated at opening can work for $Text to TeX but LaTeX citation support within Tinderbox might get more complex. I think that aligns with your note:

Thus, each exporting note generating a ‘bare’ .tex TeX file, and the assumption being that all citation work would be done outside Tinderbox

I truly have been reading up on all this. There are c.15 books on citation and copy-editing at my elbow and a plethora of web resources and TeX editiors … none with a clear answer. :frowning:

I’m not sure if this has helped any!

A wrinkle for those using Bookends as their reference manager and if mainly/only using LaTeX for their papers is to do the following in Bookends settings:

  • Select the BibTeX tab of Settings
  • Tick the Enable BibTeX for references and “Copy Citation” copies Citekey field boxes.
  • In the later use \cite in the Precede with: box.
  • Select the Scan & Bib tab of Settings.
  • For Temporary citations select {} option

Now in Bookends menu EditCopy Citation (⌘+Y), will load the selected reference’s citekey to the clipboard, e.g. \cite{bernstein:2025:infocity} which can be pasted into your Tinderbox note $Text as the citation point.

As Bookends’s formatted bibliography/reference list is generated for the ‘Hits’ query, it is a good idea to make a ‘static group’ for references you are using. Then tick all items in that group, the ticked items being what are regarded as ‘hits’. When the final list is needed, use Bookends menu BiblioBibliography… to generate the .bib file for your LaTeX project.

1 Like

Thanks for your work, Mark. Until now, I’ve been using LaTeX code in Tinderbox and exporting my notes to Texifier by copying and pasting. The drawback with this method is that the section code is inserted at the beginning of each note as follows: \chapter{} or \section{}, for instance. This also forces me to rewrite the title of each note. It seems to me that it was possible to do this differently, by inserting LaTeX code as attributes. More specifically, how do I do for ensuring that each note in a container is exported with its own section? (in the following order : \chapter, \section, \subsection). Could you please tell me how I could do that?

My TBX was a just a demo, and also reflected that everyone will work slightly differently (for all sorts of valid reasons).

I suspect this is more easily done using existing features. If you need each notes to begin with something like \chapter{}, then make a template like so:

\chapter{^value($Name)^}
^text^

If you only the $Text in LaTeX form, then use this:

^text^

The point is your choice of template and how much extra content is or is not added to ^text^ is under your control.

My ‘LaTeX_Test.tbx’ demo, up-thread, includes two templates directed at LaTeX output. Template ‘export-text’ has this code, for just the $Text of a note in LaTeX:

^text^

and template ‘LaTeX template’ has this code, for extra LaTeX at start/end of the note:

\documentclass{article}
% ulem package allows underline, strikethrough
\usepackage{ulem}  
\begin{document}
^text^
\end{document}

I’ll address the other question in a separate reply.

So for notes needing to export as a LaTeX ‘section’, the template they need is this:

\section{^value($Name)^}
^text^

I assume the section name is the name of the note. It also assumes the $Name doesn’t include any LaTeX special characters that need escaping.

The \section{} and similar are normally place of a discrete line but no following blank line is needed, q.v. defining discrete paragraphs.

A note needing a Chapter marker can use a template like so:

\chapter{^value($Name)^}
^text^

If you are more methodical in your outline structure, the you could have prototypes for chapters, sections, subsections, etc. with appropriate templates.

Bear in mind there can’t be a one-size-fits all solution, and moving from user defined features like template to built-in features, the feature gets expensive is only build for one or two people. For ROI, people think of initial engineering build cost, but overlook the long tail of maintenance over the life of the app.

Does this address the issue?

†. I’m assuming LaTeX users already know what those are (they are easily looked up) and have a process to avoid or escape them. For instance, if one’s subject matter perforce includes these characters you might create a custom function to escape them. Pass in the text string, check in turn for each special chapter and insert a backslash in front oof each instance found and then return the string. [ping @eastgate, alongside possible extra attributes, consider a latexEncode() operator. ‘Encode’ not Escape’ to fit the naming of existing escape functions, e.g. jsonEncode().

Thank you for this invaluable help! As is, it works perfectly! But I do indeed use several types of sections: chapter, section, subsection, subsubsection. Therefore, I need to create several note templates for each section. Hence my two questions:

1. How do I create a template for each section if I can’t duplicate an existing LaTeX note template?

2. How do I export multiple notes at once if I can’t copy and paste them all?

1 Like

You might not need to create multiple templates.

For example, suppose notes with $OutlineDepth of 2 are chapters, and their children are sections. Then you could do something like this:

^if($OutlineDepth==2) \chapter{^value($Name)^}
^else \section{^value($Name)^}
^endif

Or, you could have an attribute $LatexStart that might contains a string like \section{Civilization and its Discontents}. Then

^value($LatexStart)

Gives you a header if the note has a $LatexStart and no header if it doesn’t.

Usually, you export all the (exported notes) through File ▸ Export ▸ as HTML. Keep in mind that you can ^include notes in templates (or in the text of notes), or that a container can incorporate ^children in its export.

1 Like

FWIW, it would help to know if you are working on a map (all notes are at the same $OutlineDepth) or in outline, e.g. chapter notes containing section notes that contain sub-section notes. For what you are describing, I think Outline working, with nested notes makes things much easier. But, I accept that may not always be possible/desirable for the author.

Why would you need to duplicate a template. The whole point of a template is you generally use one for many notes. Here you would need some different templates: e.g. a Chapter note template vs a section note template. But done correctly, each section note ought to be able to to use the same template.

I’m interested as to why you think different sections would need different templates? I sense there is some as-yet unrevealed information relating to the structure of the document.

The normal method is to export the notes and then copy paste from each file. But if you want to only do one copy, simply set the outline and template structure so you copy/paste (or export) from one note (or file).

If the latter seems improbable, consider aTbRef’s sitemap. I know it is HTML, but the same principle applies One note creates/exports all the content.

One might be able to do the latter from a Map view but it would take some extra effort, knowledge and planning.

1 Like

Please excuse me if my request concerns basic Tinderbox concepts that I should know and have mastered by now—since 2009—when I started using that extraordinary tool. I’ve spent some time trying to understand how the LaTeX_Test file works, but I can’t understand how to export an entire container at once. What I’ve managed to show in these two screenshots below is that each level of my container has LaTeX markup: chapter, section.

I can also export a note with LaTeX markup, which is great! But I’d like to export my entire container—a chapter, a section, a subsection—all at once, and that’s what I can’t seem to do.

1 Like

naupaka:

My thought was largely in line with yours (using existing export machinery), but maybe the activation energy could be lowered just a tad with something like a document-level preference to export to TeX instead of html, and then the various export group values could be changed automagically. People who want to use TeX for writing likely already have TeX installed, so Tinderbox’s job would just be to produce the .tex file, not to render it or handle all of the extra things associated with that.

@mwra FWIW, a quasi-doc level preference can be achieved now, by adding a built-in (‘LaTeX’) prototype and two built-in templates (‘LaTeX document’ and ‘LaTeX’ text). That only requires adding the source data for those ‘notes’ into the app and adding a few menu items. Either the prototype or the template can set attributes like the export file extension and other non-HTML specific export features.

I just reread the entire thread to make sure I hadn’t missed anything. The difficulty I’m encountering seems to be the one you pointed out: while I’ve managed to assign a section level—\chapter, \section—to each note in my file, I can’t seem to export all my notes.

The only option I can think of for exporting an entire container in Texifier would be to copy and paste each note individually or to have a single note containing all my notes, but without \chapter or \section. If this export functionality existed, it would be fantastic. But perhaps I’m mistaken, and perhaps there’s a way to export all my notes at once?

Yes, there are two ways:

  • Export the whole document. But that means disabling export lots of notes you don’t need to export
  • design templates that cascade down an outline branch.

The latter makes more sense and it what your helpful screen grab above suggests. I’ll try and build a simple demo TBX for you a bit later today (have to go out now). I suspect seeing all the part in a working model will make it easier for you to customise it for your needs.

More … later!

2 Likes

Right, here is the demo: LaTeX-multi-note-export01.tbx (137.2 KB). Select note 'The document root container" and then preview it and see its descendant notes included in the export output.

I’ve had to edit the built-in LaTeX prototype a bit to get things working but this gives you an idea:

It is difficult to write a demo that covers all uses, but I think it shows the concept holds.

Here, I’ve adopted @eastgate’s strategy and used one template for the cascade, with the template using conditional (^if()^) sections in the template. Another solution is to use a different template per type of note: there is no one ‘right’ way.

I’ve also included a user function latexEncode() (not called in the demo) that will ‘escape’ the 10 LaTeX special characters. It might not be obvious to a casual LaTeX user that inline &, %, and _ potentially break their LaTeX from rendering.

There are 2 user attributes used ,LaTeXName and LaTeXRole, see the description in Inspector for the demo file to see their intent.

There is much more one could do in this demo, but the more one adds, the more user-specific everything gets. :slight_smile:

The demo notes’ $Text is from Paul Otlet’s Le Livre sur Le Livre via the Internet Archive (here). Yes, that Paul Otlet, he of the Mundaneum (see), remnants of which one can still find in a museum in Mons (Belgium). It seemed appropriately hypertextual as a source, though the text used if as filler, not meant for sense as a whole.

2 Likes

I think these are the correct settings for generating TeX code via HTML export. Note is it has some difference from the current prototype. I’ve used a literal \n for line breaks. If correcting your values use Shift+Enter to insert a line break into attribute boxes.

$HTMLBoldEnd: "}"
$HTMLBoldStart: "\textbf{"
$HTMLCloud1End: ""
$HTMLCloud1Start: ""
$HTMLCloud2End: ""
$HTMLCloud2Start: ""
$HTMLCloud3End: ""
$HTMLCloud3Start: ""
$HTMLCloud4End: ""
$HTMLCloud4Start: ""
$HTMLCloud5End: ""
$HTMLCloud5Start: ""
$HTMLCodeEnd: "}"
$HTMLCodeStart: "\texttt{"
$HTMLDontExport: false
$HTMLEntities: false
$HTMLExportAfter: ""
$HTMLExportBefore: ""
$HTMLExportChildren: true
$HTMLExportCommand: ""
$HTMLExportExtension: ".tex"
$HTMLExportFileName: ""
$HTMLExportFileNameSpacer: " "
$HTMLExportPath: [calculated]
$HTMLExportTemplate: "/Templates/LaTeX Document"
$HTMLExportFileNameLowerCase: false
$HTMLExportFileNameMaxLength: 100
$HTMLFirstParagraphEnd: "\n"
$HTMLFirstParagraphStart: ""
$HTMLFont: "Menlo"
$HTMLFontsize: 13
$HTMLImageEnd: ""
$HTMLImageStart: ""
$HTMLIndentedParagraphEnd: "\n\end{quote}"
$HTMLIndentedParagraphStart: "\begin{quote}\n"
$HTMLItalicEnd: "}\n"
$HTMLItalicStart: "\textit{"
$HTMLLinkExtension: ""
$HTMLListEnd: "\end{itemize}\n"
$HTMLListItemEnd: ""
$HTMLListItemStart: "\item "
$HTMLListStart: "\n\begin{itemize}\n"
$HTMLMarkdown: false
$HTMLMarkupText: true
$HTMLOrderedListEnd: "\end{enumerate}"
$HTMLOrderedListItemEnd: ""
$HTMLOrderedListItemStart: "\item "
$HTMLOrderedListStart: "\begin{enumerate}\n"
$HTMLOverwirteImages: false
$HTMLParagraphEnd: "\n"
$HTMLParagraphStart: ""
$HTMLPreviewCommand: ""
$HTMLQuoteHTML: false
$HTMLStrikeEnd: "}"
$HTMLStrikeStart: "\sout{"
$HTMLSubscriptEnd: "}"
$HTMLSubscriptStart: "\textsubscript{"
$HTMLSuperscriptEnd: "}"
$HTMLSuperscriptStart: "\textsuperscript{"
$HTMLUnderlineEnd: "}"
$HTMLUnderlineStart: "\uline{"
$IsTemplate: false
$Marked2: false

Edit: the $HTMLUnderlineEnd: line above originally showed " >}". My error, apologies and fixed above.

Or as an action to set the prototype’s attributes:

$HTMLBoldEnd = "}";
$HTMLBoldStart = "\textbf{";
$HTMLCloud1End = "";
$HTMLCloud1Start = "";
$HTMLCloud2End = "";
$HTMLCloud2Start = "";
$HTMLCloud3End = "";
$HTMLCloud3Start = "";
$HTMLCloud4End = "";
$HTMLCloud4Start = "";
$HTMLCloud5End = "";
$HTMLCloud5Start = "";
$HTMLCodeEnd = "}";
$HTMLCodeStart = "\texttt{";
$HTMLDontExport =;
$HTMLEntities =;
$HTMLExportAfter =;
$HTMLExportBefore =;
$HTMLExportChildren =;
$HTMLExportCommand =;
$HTMLExportExtension = ".tex";
$HTMLExportFileName =;
$HTMLExportFileNameSpacer =";
$HTMLExportTemplate = "/Templates/LaTeX Document";
$HTMLExportFileNameLowerCase =;
$HTMLExportFileNameMaxLength =;
$HTMLFirstParagraphEnd = "\n";
$HTMLFirstParagraphStart = "";
$HTMLFont =;
$HTMLFontsize =;
$HTMLImageEnd = "";
$HTMLImageStart = "";
$HTMLIndentedParagraphEnd = "\n\end{quote}";
$HTMLIndentedParagraphStart = "\begin{quote}\n";
$HTMLItalicEnd = "}\n";
$HTMLItalicStart = "\textit{";
$HTMLLinkExtension = "";
$HTMLListEnd = "\end{itemize}\n";
$HTMLListItemEnd = "";
$HTMLListItemStart = "\item ";
$HTMLListStart = "\n\begin{itemize}\n";
$HTMLMarkdown = false;
$HTMLMarkupText = true;
$HTMLOrderedListEnd = "\end{enumerate}";
$HTMLOrderedListItemEnd = "";
$HTMLOrderedListItemStart = "\item ";
$HTMLOrderedListStart = "\begin{enumerate}\n";
$HTMLOverwirteImages =e;
$HTMLParagraphEnd = "\n";
$HTMLParagraphStart = "";
$HTMLPreviewCommand =;
$HTMLQuoteHTML =;
$HTMLStrikeEnd = "}";
$HTMLStrikeStart = "\sout{";
$HTMLSubscriptEnd = "}";
$HTMLSubscriptStart = "\textsubscript{";
$HTMLSuperscriptEnd = "}";
$HTMLSuperscriptStart = "\textsuperscript{";
$HTMLUnderlineEnd = "}";
$HTMLUnderlineStart = "\uline{";
$IsTemplate =;
$Marked2 = false;

Edit: the $HTMLUnderlineEnd = line above originally showed " >}". My error, apologies and fixed above.

Dear Dr.Mark Anderson,
Thank you for providing a demo of improved multi notes export in LaTeX.
With this improvement, it is no longer necessary to specify LaTeX \section etc. in the main text, which was previously done and very helpful.
I can use Japanese by simply changing documentclass[article] to \documentclass{ltjarticle} in the LaTeX Document Template.
Footnotes also function as before when written in LaTeX.
Confirmed on Mac OS Ventura TeXstudio 4.9.1 (git 4.9.1).
Yours, WAKAMATSU
P.S
I was experimenting with a similar attempt
(batch export of multiple files) using Quarto.
For Quarto format : pdf
pdf-engine: lualatex
documentclass: bxjsbook
classoption: [lualatex, ja=standard, 10pt, a4paper, textwidth-limit=50, openany] are specified in YAML.

2 Likes