Exporting Links to LaTeX

Is there any way to replace some text before or after exporting it with ^text^?
I have a TBX file with lots of notes that I want to use for a book (LaTeX→PDF) and a website. To keep the content and styling consistent, I keep the notes free from code and use only basic text formatting in the text editor. For the LaTeX export I use a LaTeX prototype with the appropriate markup in the Export Inspector. For the advanced formatting I wrote a LaTeX Template that works very well for me.
Now I have some web links inside my notes that export to:

(<a href="https://abc.de">my link</a>)

which confuses LaTeX. I’d like to change them to LaTeX hyperref syntax:

\href{https://abc.de}{my link}.

Of course, I can replace the link code using RegEx in my LaTeX template by replacing ^text^ with

^value($Text.replace("\(<a href="(.+)">(.+)</a>\)","\\href{$1}{$2}"))^

but then I lose the markup provided by ^text^.
Any idea how to solve this?

This topic hasn’t come up for a bit but you might want to check this article on using LaTeX. I think others are using Markdown-based ‘HTML’ export to Pandoc and exporting LaTeX from there (but I’m less clear on the detail).

Thanks for the prompt reply! This article covers the basics but warns that some aspects of HTML markup, such as the link formatting, cannot be altered. But meanwhile I’ve found a solution…
Here’s how:

  1. Define a string attribute $Text_LaTeX for the “top level” note used for exporting
  2. Set up another LaTeX template "LaTeX postprocessing":

^action($Text_LaTeX=exportedString(this,"/Templates/LaTeX document"))^ ^value($Text_LaTeX.replace('\(<a href="(.+)">(.+)</a>\)',"\\footnote{\\href{$1}{$2}}"))^

  1. Change the Export Template of the aforementioned “top level” note to the newly created Export Template.

This Template will do the following:

  • translate the document to LaTeX according to the given markup rules
  • store this text (which is plain text, but still contains the HTML syntax for the Links) in the $Text_LaTeX attribute
  • export the content of this attibute after replacing the HTML with LaTeX links

I am surprised HOW smoothly this works and how fast Tinderbox manages the conversion. The result is displayed immediately in the export tab.

Thanks for your hint!

2 Likes