1

I'm writing a document in which i talk about many URIs (inline). To not clutter readability too much, i'd like to define and use CURIEs instead (this is common in the Semantic Web community). So rather than talking about http://dbpedia.org/resource/Dog i'd like to talk about dbr:Dog.

Currently i have some code like this in my preamble:

\newcommand{\curiesize}{\small}
\newcommand{\defcurie}[2]{%
  \expandafter\newcommand\csname#1\endcsname[1]{{\curiesize \href{#2##1}{\nolinkurl{#1:##1}}}}%
}
\defcurie{rdf}{http://www.w3.org/1999/02/22-rdf-syntax-ns\#}
\defcurie{rdfs}{http://www.w3.org/2000/01/rdf-schema\#}
\defcurie{owl}{http://www.w3.org/2002/07/owl\#}
\defcurie{dbr}{http://dbpedia.org/resource/}
...
\defcurie{foaf}{http://xmlns.com/foaf/0.1/}

So in the document i can then write something like \dbr{Dog} to refer to dbr:Dog.

As the list above gets longer and longer i'd like to extend the \defcurie meta-command to somewhere remember the CURIE prefixes and later print a glossary like listing in the front- or backmatter.

Any recommendations how to do that?

1

Fiddling around with this some more, i found a first way to solve this myself by extending the preamble meta-command like this:

\newcommand{\usedprefixes}{} % used to store `prefix: & \url{uri} \\` like table rows
\newcommand{\defcurie}[2]{%
  \expandafter\def\expandafter\usedprefixes\expandafter{\usedprefixes\texttt{#1}: & \begin{small}\url{#2}\end{small} \\[1ex] }
  \expandafter\newcommand\csname#1\endcsname[1]{{\curiesize \href{#2##1}{\nolinkurl{#1:##1}}}}%
}

Then later in the document do something like this:

\chapter*{List of URI Prefixes (CURIEs)}
  \begin{tabular}{@{}ll}
    \usedprefixes
  \end{tabular}

Still interested in better/cooler approaches though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.