2

I am writing a book with several chapters and sections that are linked with each other by the use of \ref. Now I would like to get an overview of the starting points and targets of these \ref and \pageref links.

Is there a way to extract a list of \ref and \pageref including the page number of their occurrence and the page number of their target?

The data set could look as follow:

type, source, target
pageref, 10, 122
ref, 11, 43

Finally the data could be visualized in a chord diagram, so the reader would get an alternative representation on how different sections relate to each other:

enter image description here

Further more, it would be nice to do the same for all citations to get a glue about the amount of references per chapter/section/subsection.

UPDATE So far I was playing with the following files * .aux file: There are all \ref stored, but without any page number * post script file: if converted to text, at least some regex could collect snippets like "see page ...". It would be helpful to process post script as human readable code.

1
  • You're taking the piss, I assume ;).
    – cfr
    Jan 20, 2016 at 0:23

1 Answer 1

2

You can try rdfref package. It unfortunately isn't on CTAN, because it doesn't have any documentation, only an example of usage.

You haven't provided any example, so I will add some:

\documentclass{article}

\usepackage{lipsum}
\usepackage{rdfref-user,rdfref-query,nameref}
\usepackage{newfile}
\newoutputstream{references}
\openoutputfile{\jobname.ref}{references}

\begin{document}
\inputontology{theorem-ontology.tex}
\section{first}
\rdflabel{sec:first}

Some references, to section~\rdfref{sec:second} on page~\rdfpageref{sec:second}
\lipsum[1-10]

\section{second}
\rdflabel{sec:second}

Now some other references, to section~\rdfref{sec:first} on page~\rdfpageref{sec:first}

\Bind{?ref}{doc:refersTo}{?obj}{%
  \addtostream{references}{
    \GetValProperty{?ref}{rdf:type}
    \GetValProperty{?ref}{doc:pageNo}
    \GetValProperty{?obj}{doc:pageNo}
  }
}
\end{document}

It uses rdfref commands, \rdfref, \rdfpageref and \rdflabel, you can use something like let\label\rdflabel if you want to modify default LaTeX commands to use rdfref features.

\inputontology{theorem-ontology.tex}

loads default properties for sections and some other referenced type objects. Properties for objects are saved in the .aux file:

\relax 
\LoadTriple {sec:sectioning}{rdfs:label}{Sectioning}
\LoadTriple {sec:sectioning}{rdf:type}{rdfs:Class}
\LoadTriple {thm:theorem}{rdfs:label}{Theorem}
\LoadTriple {thm:theorem}{rdf:type}{rdfs:Class}
\LoadTriple {thm:proposition}{rdfs:label}{Proposition}
\LoadTriple {thm:proposition}{rdf:type}{rdfs:Class}
\LoadTriple {thm:proposition}{rdfs:subClassOf}{thm:theorem}
\LoadTriple {thm:lemma}{rdfs:label}{Lemma}
\LoadTriple {thm:lemma}{rdf:type}{rdfs:Class}
\LoadTriple {thm:lemma}{rdfs:subClassOf}{thm:theorem}
\LoadTriple {eq:equation}{rdfs:label}{Equation}
\LoadTriple {eq:equation}{rdf:type}{rdfs:Class}
\LoadTriple {eq:equation}{rdfs:subClassOf}{thm:theorem}
\LoadTriple {rdfs:Class}{rdfs:label}{Class}
\LoadTriple {sec:first}{doc:hasParent}{\RootObject }
\LoadTriple {sec:first}{doc:envir}{document}
\LoadTriple {sec:first}{rdf:type}{sec:sectioning}
\@writefile{toc}{\contentsline {section}{\numberline {1}first}{1}}
\newlabel{sec:first}{{1}{1}{first}{}{}}
\LoadTriple {sec:first}{doc:pageNo}{1}
\LoadTriple {sec:first}{rdfs:label}{1\ first}
\LoadTriple {sec:first}{doc:label}{1}
\LoadTriple {_:blank1}{doc:hasParent}{sec:first}
\LoadTriple {_:blank1}{doc:pageNo}{1}
\LoadTriple {_:blank1}{doc:refersTo}{sec:second}
\LoadTriple {sec:second}{doc:referedBy}{_:blank1}
\LoadTriple {_:blank1}{rdfs:label}{Blank node: blank1}
\LoadTriple {_:blank1}{rdf:type}{doc:reference}
\LoadTriple {_:blank2}{doc:hasParent}{sec:first}
\LoadTriple {_:blank2}{doc:pageNo}{1}
\LoadTriple {_:blank2}{doc:refersTo}{sec:second}
\LoadTriple {sec:second}{doc:referedBy}{_:blank2}
\LoadTriple {_:blank2}{rdfs:label}{Blank node: blank2}
\LoadTriple {_:blank2}{rdf:type}{doc:pagereference}
\LoadTriple {sec:second}{doc:hasParent}{sec:first}
\LoadTriple {sec:second}{doc:envir}{document}
\LoadTriple {sec:second}{rdf:type}{sec:sectioning}
\@writefile{toc}{\contentsline {section}{\numberline {2}second}{3}}
\newlabel{sec:second}{{2}{3}{second}{}{}}
\LoadTriple {sec:second}{doc:pageNo}{3}
\LoadTriple {sec:second}{rdfs:label}{2\ second}
\LoadTriple {sec:second}{doc:label}{2}
\LoadTriple {_:blank3}{doc:hasParent}{sec:second}
\LoadTriple {_:blank3}{doc:pageNo}{3}
\LoadTriple {_:blank3}{doc:refersTo}{sec:first}
\LoadTriple {sec:first}{doc:referedBy}{_:blank3}
\LoadTriple {_:blank3}{rdfs:label}{Blank node: blank3}
\LoadTriple {_:blank3}{rdf:type}{doc:reference}
\LoadTriple {_:blank4}{doc:hasParent}{sec:second}
\LoadTriple {_:blank4}{doc:pageNo}{3}
\LoadTriple {_:blank4}{doc:refersTo}{sec:first}
\LoadTriple {sec:first}{doc:referedBy}{_:blank4}
\LoadTriple {_:blank4}{rdfs:label}{Blank node: blank4}
\LoadTriple {_:blank4}{rdf:type}{doc:pagereference}

\LoadTriple has three parameters, first is an object, second is property and third value. Each \rdflabel produces object named as label and save some properties, such as what type it is (section, figure, etc) or page number. Each \rdfref and \rdfpageref produces so called blank node, which is anonymous object, with properties such as destination object, page number etc.

rdfref provides query mechanism for retrieving property values, \Bind command:

\Bind{?ref}{doc:refersTo}{?obj}{%
  \addtostream{references}{
    \GetValProperty{?ref}{rdf:type}
    \GetValProperty{?ref}{doc:pageNo}
    \GetValProperty{?obj}{doc:pageNo}
  }
}

It has four parameters, first three correspond to object, property, value schema, fourth is the code to be executed. Parameters which start with ? are variables which are looked up. So in our example, we search for all objects with property doc:refersTo, which is automatically created for all \rdfref and \rdfpageref commands. Using \GetValProperty we can retrieve propery for a variable. We need to get reference type (ref or pageref) and page for reference and page number of the referenced object. These properties are then saved in file named texfilename.ref. It's contents for our example are:

 doc:reference 1 3 
 doc:pagereference 1 3 
 doc:reference 3 1 
 doc:pagereference 3 1 

Edit:

regarding citations, we can utilize biblatex hooks and data accessing commands. Save following code as biblatex-ontology.tex:

\AddRdfType{bib}{
  \AddPropertyEx{rdf:type}{bib:bibitem}
  \AddPropertyEx{doc:pageNo}{\thepage}
  \AddPropertyEx{rdfs:label}{Bibitem: \strfield{entrykey}}
}


\WithObject{bib:bibitem}{%
  \AddProperty{rdfs:label}{Bibitem}
  \AddProperty{rdf:type}{rdfs:Class}
}

\makeatletter
\@ifpackageloaded{biblatex}{%
  \AtEveryBibitem{%
    \bgroup%
      \let\ParentObject\CurrentObject%
      \edef\CurrentObject{\strfield{entrykey}}%
      % save defalt properties for bib type
      \csuse{rdf:type@bib}%
      \egroup%
  }%
  \AtEveryCitekey{%
    % use default properties for referencing commands
      \rdfref@core{\strfield{entrykey}}{\AddProperty{rdf:type}{bib:citation}}%
  }
}{}
\makeatother

Important commands are \AtEveryBibitem and \AtEveryCitekey which saves information about bibitem and citation.

Modified document which uses biblatex and our new ontology:

\documentclass{article}

\usepackage{lipsum}
\usepackage{rdfref-user,rdfref-query,nameref}
\usepackage{newfile}
\usepackage{biblatex}
\addbibresource{biblatex-examples.bib}
\newoutputstream{references}
\openoutputfile{\jobname.ref}{references}

\inputontology{theorem-ontology.tex}
\inputontology{biblatex-ontology.tex}
\begin{document}
\section{first}
\rdflabel{sec:first}

Some references, to section~\rdfref{sec:second} on page~\rdfpageref{sec:second}

Some citations: \cite{bertram}

\lipsum[1-10]

\section{second}
\rdflabel{sec:second}

Now some other references, to section~\rdfref{sec:first} on page~\rdfpageref{sec:first}

\Bind{?ref}{doc:refersTo}{?obj}{%
  \addtostream{references}{
    \GetValProperty{?ref}{rdf:type}
    \GetValProperty{?ref}{doc:pageNo}
    \GetValProperty{?obj}{doc:pageNo}
  }
}
\printbibliography
\end{document}

the .ref file now contains:

 doc:reference 1 3 
 doc:pagereference 1 3 
 bib:citation 1 3 
 doc:reference 3 1 
 doc:pagereference 3 1 

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.