Skip to content

rdfref, lualatex, dot2tex, --shell-escape works, but not with --output-dir #113

Description

@ouboub

Hi right now on rdfref a package is developed that extracts the information about references of equation and theorems and generate a dependency graph using dot2tex. I will attach an example below.

What works is

  1. run lualatex equation-graph.tex
  2. dot2tex –figonly –autosize -t raw -o complex-graph.tmp complex-graph.dot
  3. dot2tex –figonly –autosize -t raw -o build/complex-graph.tmp build/complex-graph.dot

Now in order not to run dot2tex explicitly one can use the –shell-escape option here is an example, called complex

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\numberwithin{equation}{section}
\usepackage{tikz}
\usepackage{shellesc}
\usetikzlibrary{graphs,graphdrawing,calc} 
\usegdlibrary{layered}
\usepackage[T1]{fontenc}
\usepackage{rdfref}
\NewDocumentEnvironment{rdfequation}{o +b}{
  \begin{equation}
    #2 
    \IfBlankF{#1}{
      \rdflabel{#1}
      \AssignProperty{#1}{eq:value}{$#2$}
    }
  \end{equation}
}{}

\newwrite\graphwrite

\makeatletter
\newcommand\graphout[1]{\protected@write\graphwrite{\let\owrite\write\def\write{\immediate\owrite}}{#1}}

% #1 name of the graph (default \jobname-graph) -- it needs to be different than name of any existing file!
% #2 RDF property to be printed
% #3 list of allowed rdf:type for objects
% #4 list of allowed rdf:type for subjects
% don't forget to call latex with --shell-escape 
\NewDocumentCommand\RdfDrawGraph{O{\jobname-graph} O{rdfs:label} m m}{%
  \immediate\openout\graphwrite=#1.dot\relax%
  \graphout{digraph hello\@charlb} % save graph header
  \RdfLoopReferences{#3}{#4}{%
    \StrSubstitute{\currentobject}{:}{_}[\objectlabel]
    \StrSubstitute{\currentsubject}{:}{_}[\subjectlabel]
    \graphout{\objectlabel [shape="rectangle",texlbl="\GetProperty{\currentobject}{#2}"]}
    \graphout{\subjectlabel [shape="rectangle",texlbl="\GetProperty{\currentsubject}{#2}"]}
    \graphout{\objectlabel-> \subjectlabel} %
  }
  \graphout{\@charrb}% save footer
  \immediate\closeout\graphwrite%
  \ShellEscape{dot2tex --figonly --autosize -t raw -o #1.tmp #1.dot }%
  \InputIfFileExists{#1.tmp}{}%
}
\makeatother

\newcommand\renewrdfenvironment[1]{% 
  \expandafter\let\csname orig:#1\expandafter\endcsname\csname#1\endcsname%
  \expandafter\let\csname endorig:#1\expandafter\endcsname\csname end#1\endcsname%
  \RenewDocumentEnvironment{#1}{o +b}{
  \begin{orig:#1}%
    ##2%
    \IfBlankF{##1}{%
      \rdflabel{##1}%
      \AddTriple{##1}{eq:value}{$##2$}%
    }
  \end{orig:#1}%
}{}%
}
\renewrdfenvironment{equation}
\robustify\int
\begin{document}

% we need to declare some properties for the eq: prefix 
\AddRdfType{eq}{
  \AddPropertyEx{rdf:type}{eq:equation}
  \AddPropertyEx{doc:pageNo}{\thepage}
  % this will be used in the graph label, change to your liking
  \AddPropertyEx{rdfs:label}{Equation \theequation}
}

\makeatletter
\AddRdfType{sec}{
  \AddPropertyEx{rdf:type}{sec:sectioning}
  \AddPropertyEx{doc:pageNo}{\thepage}
  % this will be used in the graph label, change to your liking
  \AddPropertyEx{rdfs:label}{Section \@currentlabel}
}
\makeatother

\section{first section}
\rdflabel{sec:first}
\begin{equation}[eq:hello]
  \begin{aligned}
    \sqrt{E(t)} & \leq e^{-\varkappa(t-t_0)}\sqrt{E(t_0)} + \varkappa^2\int_{t_0}^te^{-\varkappa(t-s)} \left\Vert u_h(s) \right\Vert_{H^{m}}ds \\
            & + \int_{t_0}^te^{-\varkappa (t-s)}e^{-\varkappa s} \left\Vert a(s,\cdot) \left( 1+u(s) \right)^3 \right\Vert_{H^m}ds
  \end{aligned}.
\end{equation}

This equation links to equation~\rdfref{eq:second}, as well as to equation~\rdfref{eq:third}.

\begin{equation}[eq:1]
\begin{aligned}
       \sqrt{E(t)}
       & \leq
         e^{-\varkappa t}\sqrt{E(0)} + \varkappa^2\int_{0}^te^{-\varkappa (t-s)} \alpha\beta ds + \int_{0}^te^{-\varkappa (t-s)}e^{-\varkappa s} \left\Vert a(s,\cdot) \left( 1+u(s) \right)^3 \right\Vert_{H^m} ds\\       & \leq
                                                                                                                                                       e^{-\varkappa t}\sqrt{E(0)} +\varkappa \left(1 -e^{-\varkappa t}\right)\alpha\beta+ te^{-\varkappa t}\sup_{[0,t]}\left\Vert a(s,\cdot) \left( 1+u(s) \right)^3 \right\Vert_{H^m}.
     \end{aligned} 
\end{equation}

This links to~\rdfref{eq:hello}.
\section{another}
\rdflabel{sec:another}

\begin{equation}[eq:second]
  e^{\varkappa t} \sqrt{E(t)} \leq \sqrt{E(0)} +\varkappa \left(e^{\varkappa t} -1 \right)\alpha\beta+ t\sup_{[0,t]}\left\Vert a(s,\cdot) \left( 1+u(s) \right)^3 \right\Vert_{H^m}.
\end{equation}

Link to another equation~\rdfref{eq:third}, in section~\rdfpageref{sec:first}.
\begin{equation}[eq:third]
    E(t)\leq E(0)
\end{equation}
\RdfLoopReferences{}{eq:equation,sec:sectioning}{%
  \GetProperty{\currentobject}{rdfs:label} -> \GetProperty{\currentsubject}{rdfs:label}, %
}

\RdfDrawGraph[\jobname-graph][eq:value]{}{eq:equation}
\end{document}

Then lualatex --shell-escape working-example-equation.tex works

working-example-equation.pdf

but lualatex --shell-escape --output-dir=build working-example-equation.tex does not.

So the problem seems that the output-dir should be defined in for the shell-escape command.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\numberwithin{equation}{section}
\usepackage{tikz}
\usepackage{shellesc}
\usetikzlibrary{graphs,graphdrawing,calc} 
\usegdlibrary{layered}
\usepackage[T1]{fontenc}
\usepackage{rdfref}
\NewDocumentEnvironment{rdfequation}{o +b}{
  \begin{equation}
    #2 
    \IfBlankF{#1}{
      \rdflabel{#1}
      \AssignProperty{#1}{eq:value}{$#2$}
    }
  \end{equation}
}{}

\newwrite\graphwrite



\makeatletter
\newcommand\graphout[1]{\protected@write\graphwrite{\let\owrite\write\def\write{\immediate\owrite}}{#1}}

\def\BuildDir{build/}
% #1 name of the graph (default \jobname-graph) -- it needs to be different than name of any existing file!
% #2 RDF property to be printed
% #3 list of allowed rdf:type for objects
% #4 list of allowed rdf:type for subjects
% don't forget to call latex with --shell-escape 
\NewDocumentCommand\RdfDrawGraph{O{\jobname-graph} O{rdfs:label} m m}{%
  \immediate\openout\graphwrite=#1.dot\relax%
  \graphout{digraph hello\@charlb} % save graph header
  \RdfLoopReferences{#3}{#4}{%
    \StrSubstitute{\currentobject}{:}{_}[\objectlabel]
    \StrSubstitute{\currentsubject}{:}{_}[\subjectlabel]
    \graphout{\objectlabel [shape="rectangle",texlbl="\GetProperty{\currentobject}{#2}"]}
    \graphout{\subjectlabel [shape="rectangle",texlbl="\GetProperty{\currentsubject}{#2}"]}
    \graphout{\objectlabel-> \subjectlabel} %
  }
  \graphout{\@charrb}% save footer
  \immediate\closeout\graphwrite%
  \ShellEscape{dot2tex --figonly --autosize -t raw -o \BuildDir#1.tmp \BuildDir#1.dot }%
  \InputIfFileExists{#1.tmp}{}%
}

\makeatother

\newcommand\renewrdfenvironment[1]{% 
  \expandafter\let\csname orig:#1\expandafter\endcsname\csname#1\endcsname%
  \expandafter\let\csname endorig:#1\expandafter\endcsname\csname end#1\endcsname%
  \RenewDocumentEnvironment{#1}{o +b}{
  \begin{orig:#1}%
    ##2%
    \IfBlankF{##1}{%
      \rdflabel{##1}%
      \AddTriple{##1}{eq:value}{$##2$}%
    }
  \end{orig:#1}%
}{}%
}


\renewrdfenvironment{equation}
\robustify\int
\begin{document}

% we need to declare some properties for the eq: prefix 
\AddRdfType{eq}{
  \AddPropertyEx{rdf:type}{eq:equation}
  \AddPropertyEx{doc:pageNo}{\thepage}
  % this will be used in the graph label, change to your liking
  \AddPropertyEx{rdfs:label}{Equation \theequation}
}

\makeatletter
\AddRdfType{sec}{
  \AddPropertyEx{rdf:type}{sec:sectioning}
  \AddPropertyEx{doc:pageNo}{\thepage}
  % this will be used in the graph label, change to your liking
  \AddPropertyEx{rdfs:label}{Section \@currentlabel}
}
\makeatother

\section{first section}
\rdflabel{sec:first}
\begin{equation}[eq:hello]
  \begin{aligned}
    \sqrt{E(t)} & \leq e^{-\varkappa(t-t_0)}\sqrt{E(t_0)} + \varkappa^2\int_{t_0}^te^{-\varkappa(t-s)} \left\Vert u_h(s) \right\Vert_{H^{m}}ds \\
            & + \int_{t_0}^te^{-\varkappa (t-s)}e^{-\varkappa s} \left\Vert a(s,\cdot) \left( 1+u(s) \right)^3 \right\Vert_{H^m}ds
  \end{aligned}.
\end{equation}

This equation links to equation~\rdfref{eq:second}, as well as to equation~\rdfref{eq:third}.

\begin{equation}[eq:1]
\begin{aligned}
       \sqrt{E(t)}
       & \leq
         e^{-\varkappa t}\sqrt{E(0)} + \varkappa^2\int_{0}^te^{-\varkappa (t-s)} \alpha\beta ds + \int_{0}^te^{-\varkappa (t-s)}e^{-\varkappa s} \left\Vert a(s,\cdot) \left( 1+u(s) \right)^3 \right\Vert_{H^m} ds\\       & \leq
                                                                                                                                                       e^{-\varkappa t}\sqrt{E(0)} +\varkappa \left(1 -e^{-\varkappa t}\right)\alpha\beta+ te^{-\varkappa t}\sup_{[0,t]}\left\Vert a(s,\cdot) \left( 1+u(s) \right)^3 \right\Vert_{H^m}.
     \end{aligned} 
\end{equation}

This links to~\rdfref{eq:hello}.
\section{another}
\rdflabel{sec:another}

\begin{equation}[eq:second]
  e^{\varkappa t} \sqrt{E(t)} \leq \sqrt{E(0)} +\varkappa \left(e^{\varkappa t} -1 \right)\alpha\beta+ t\sup_{[0,t]}\left\Vert a(s,\cdot) \left( 1+u(s) \right)^3 \right\Vert_{H^m}.
\end{equation}

Link to another equation~\rdfref{eq:third}, in section~\rdfpageref{sec:first}.

\begin{equation}[eq:third]
    E(t)\leq E(0)
\end{equation}
\RdfLoopReferences{}{eq:equation,sec:sectioning}{%
  \GetProperty{\currentobject}{rdfs:label} -> \GetProperty{\currentsubject}{rdfs:label}, %
}

\RdfDrawGraph[\jobname-graph][eq:value]{}{eq:equation}
\end{document}

but this does not work, that is
lualatex --shell-escape working-example-equation-out.tex
does not generate the graph

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions