Skip to content

Instantly share code, notes, and snippets.

@white-gecko
Last active May 3, 2021 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save white-gecko/5595112 to your computer and use it in GitHub Desktop.
Save white-gecko/5595112 to your computer and use it in GitHub Desktop.
This is a LaTeX package which provides support for prefixes in qnames. It depends on the url- and the hyperref-package
% This package provides support for prefixes in qnames
%
% Defined commands:
% \setprefix{foaf}{http://xmlns.com/foaf/0.1/}
% Define a prefix namespace
% \getprefix{foaf}
% Get a defined prefix namespace
% \prefix{foaf}
% Just output the prefix linked to the namespace
% \qname{foaf:Person} has to contain a colon
% Write a qname, where the prefix will be linkt to the defined namespace and the qualifier will be linked to the whole URI
% \mailto{arndtn@gmail.com}
% Write an email-Address and link it with a mailto: infront of it
%
%
% Changelog:
% 0.01:
% * Add \setprefix, \getprefix, \qname and \mailto
% 0.02:
% * Add \prefix
% * Add support for wrapping urls and qnames with camel caps
% * Add some commonly used prefixes (dc, dct, foaf, ov, rdf, sioc, sioct and xsd)
%
% (c) 2013 Natanael Arndt
% Thanks to all the contributors of
% - http://tex.stackexchange.com/questions/114666/create-an-array-of-variables-with-string-keys
% - http://tex.stackexchange.com/questions/114635/using-variables-in-a-command-results-in-argument-of-reserveda-has-an-extra
% - http://tex.stackexchange.com/questions/95093/automatic-line-breaking-of-camel-case-within-url
% especially to David Carlisle
%
% LPPL LaTeX Public Project License
%
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{qname}
[2013/06/13 v0.02 LaTeX package for prefix support in qnames]
\RequirePackage{hyperref}
\RequirePackage{url}
\def\setprefix#1#2{\expandafter\def\csname prefix@#1\endcsname{#2}}
\def\getprefix#1{\csname prefix@#1\endcsname}
\newcommand{\prefix}[1]{\href{\getprefix{#1}}{\nolinkurl{#1}}}
\def\qname#1{\xqname#1\\}
\def\xqname#1:#2\\{%
\href{\getprefix{#1}}{\nolinkurl{#1:}}%
\href{\getprefix{#1}#2}{\nolinkurl{#2}}%
}
\newcommand{\mailto}[1]{\href{mailto:#1}{\nolinkurl{#1}}}
% Wrapping Camel Caps
\makeatletter
\g@addto@macro\UrlSpecials{\camelurl}
\def\camelurl{%
\count@`a
\loop
\mathcode\count@"8000
\uccode`\~\count@\uppercase{\edef~{\mathchar\the\count@\noexpand\breakifupper}}%
\ifnum\count@<`\z
\advance\count@\@ne
\repeat}
\def\breakifupper#1{%
\ifcat .\noexpand#1%
\ifnum`#1>40
\ifnum`#1<91
\penalty\z@
\fi\fi\fi
#1%
}
\makeatother
% Predefined namespace prefixes
\setprefix{dc}{http://purl.org/dc/elements/1.1/}
\setprefix{dct}{http://purl.org/dc/terms/}
\setprefix{foaf}{http://xmlns.com/foaf/0.1/} % http://xmlns.com/foaf/spec/\#term_
\setprefix{ov}{http://open.vocab.org/docs/}
\setprefix{rdf}{http://www.w3.org/1999/02/22-rdf-syntax-ns\#}
\setprefix{sioc}{http://rdfs.org/sioc/ns\#} % http://rdfs.org/sioc/spec/\#term_
\setprefix{sioct}{http://rdfs.org/sioc/types\#}
\setprefix{xsd}{http://www.w3.org/2001/XMLSchema\#}
\endinput
%%
%% End of file `qname.sty'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment