[texhax] maintaining a database map for latex

martin f krafft madduck at madduck.net
Sun Sep 20 15:25:09 CEST 2009

also sprach martin f krafft <madduck at madduck.net> [2009.09.20.1241 +0200]:
> I want to replace links in a book with "QuickLinks", e.g.
> http://debian.org would be rendered as
> http://mybooksite/quicklinks/123 or similar. Can LaTeX help me with
> this?

Let me give an example. Let's assume I have a paragraph like this
(please don't hold the stupidity of this example against me):

  Debian (\link{http://debian.org}) is a free operating system
  (\link{http://en.wikipedia.org/wiki/Operating\_system}) and it has
  a webpage: \link{http://debian.org}

Given this in a .tex file, what I would really like is two things:

1. LaTeX renders this into a DVI or PDF so that it reads:

      Debian (QuickLink #1) is a free operating system (QuickLink
      #2) and it has a webpage: QuickLink #1.

   The way LaTeX would do this is by maintaining a map from link to
   ID, e.g.

      http://debian.org                              --> 1
      http://en.wikipedia.org/wiki/Operating\_system --> 2

    and whenever I called \link{}, it would find out the ID for the
    link, or create a new entry with the next ID and use that.
    \link{} would then be something like

      \newcommand{\link}[1] {QuickLink \#\getlinkid{#1}}

2. In addition to the PDF, I would also like to have a file, e.g.
   links.map, which contained the aforementioned map, so that I can
   then use it for the purpose of the CGI. Then, if the CGI gets
   a request for e.g. http://mybooksite.com/quicklinks/2, it would
   consult the map, obtain the Wikipedia link, and redirect the
   client there.

The benefit of all this is that it's easier for the user to type
such a link (copying it from a book), and that a webpage can move to
a new URL and I can update it post-publication in one place. If
a link moves, I change it in the document, re-run latex, and feed
the new map to the CGI.

All this is trivial (well, not hard anyway) to do outside of LaTeX,
and I could obviously get a list of all links, create IDs for them,
and then search-replace the .tex file accordingly, but I would
really prefer to keep the data in the text, which will make future
revisions a lot easier.


martin | http://madduck.net/ | http://two.sentenc.es/
"i always had a repulsive need to be something more than human."
                                                      -- david bowie
spamtraps: madduck.bogus at madduck.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature (see http://martin-krafft.net/gpg/)
URL: <http://tug.org/pipermail/texhax/attachments/20090920/6f105abb/attachment.bin>

More information about the texhax mailing list