michal-h21 / rdfref

Cross-referencing system for LaTeX, inspired with RDF
16 stars 2 forks source link

How to add a new environment? #4

Closed ouboub closed 1 year ago

ouboub commented 1 year ago

Hi I tried to add a new environment, a corollary. I don't understand why I cannot just use the newtheorem command, but anyhow so I added

\declaretheorem[name=Corollary,Refname={Corollary,Corollaries}]{cor}

to the theorems-sample.tex file and

\AddRdfType{cor}{%
\AddProperty{rdf:type}{thm:corollary}
\AddPropertyEx{doc:pageNo}{\thepage}
\AddPropertyEx{rdfs:label}{\@currentlabel\ \@currentlabelname}
}

to the ontology file, I compiled and run (my generated files are in the build directory) dot -Tpng build/theorems-sample.dot -o theorem-graph.png but it did not work.

As I wrote I have forked your repository and have pushed all my changes to new branch, called default (I am a mercurial user..) Shall I set a pull request? Or send you the link (I could add you to the email notification system), I don't use much pull requests, so that is why i ask

regards

Uwe Brauer

ouboub commented 1 year ago

I think I resolved it: I have to add two entries to the ontology file, namely

\AddRdfType{cor}{%
\AddProperty{rdf:type}{thm:corollary}
\AddPropertyEx{doc:pageNo}{\thepage}
\AddPropertyEx{rdfs:label}{\@currentlabel\ \@currentlabelname}
}

and also and this I missed

\WithObject{thm:corollary}{%
\AddProperty{rdfs:label}{Corollary}
\AddProperty{rdf:type}{rdfs:Class}
\AddProperty{rdfs:subClassOf}{thm:theorem}
}

however

\AddRdfType{Corollary}{% No really necesarry
\AddProperty{rdf:type}{thm:corollary}
\AddPropertyEx{doc:pageNo}{\thepage}
\AddPropertyEx{rdfs:label}{\@currentlabel\ \@currentlabelname}
}

seems not necessary, I wish there were a minimal manual

regards Uwe Brauer

michal-h21 commented 1 year ago

The important thing here is to register the thm:corollary theorem type as rdfs:subClassOf of thm:theorem in \WithObject{thm:corollary}.

This code then collects all subclasses of the theorem class, which is then used in the theorem listing info:

% Make list of classes, which are subclasses of thm:theorem
% use query to add type #2 to list #1
% this helper list will be used to loop over all theorems
\newcommand\buildtypelist[2]{%
    \listadd#1{#2} % add searched 
    \Bind{?x}{rdfs:subClassOf}{#2}{%
        % only direct children of #2 are taken into account
        \listxadd#1{\GetVal{?x}}% must be global and expanded
    }%
}

% build list of theorems      
\buildtypelist\theoremlist{thm:theorem}