michal-h21 / rdfref

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

generation of graph fails with --output-dir="build" #14

Open ouboub opened 6 days ago

ouboub commented 6 days ago

Hi

The following example

\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
\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{rdfequation}[eq:first]
  \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{rdfequation}

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

\begin{rdfequation}[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{rdfequation}

This links to~\rdfref{eq:first}.

\section{another}
\rdflabel{sec:another}

\begin{rdfequation}[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{rdfequation}

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

\begin{rdfequation}[eq:third]
    E(t)\leq E(0)
\end{rdfequation}

\RdfLoopReferences{}{eq:equation,sec:sectioning}{%
  \GetProperty{\currentobject}{rdfs:label} -> \GetProperty{\currentsubject}{rdfs:label}, %
}

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

\end{document}

does not work with the command: lualatex --shell-escape --output-dir="build/" complex.tex

But only with lualatex --shell-escape complex.tex

What is the reason for this behaviour?

michal-h21 commented 4 days ago

The command executed with \ShellEscape is run in the current directory, not in the output dir. So you need to add the path to the output dir, like:

\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}{}%
}

Unfortunately, it doesn't work, dot2tex printed this error:

ERROR    Failed to process input
Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/dot2tex/dot2tex.py", line 3075, in main
    s = conv.convert(dotdata)
  File "/usr/lib/python3.13/site-packages/dot2tex/dot2tex.py", line 800, in convert
    return self.do_preview_preproc()
           ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/dot2tex/dot2tex.py", line 1053, in do_preview_preproc
    ok = pp.process()
  File "/usr/lib/python3.13/site-packages/dot2tex/dot2tex.py", line 2645, in process
    self.parse_log_file()
    ~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/dot2tex/dot2tex.py", line 2681, in parse_log_file
    with open(logfilename, 'r') as f:
         ~~~~^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] Adresář nebo soubor neexistuje: '/tmp/dot2texi6ka89so/dot2tex.log'

But if I run it manually, like:

$ dot2tex --figonly --autosize -t raw -o build/complex-graph.tmp build/complex-graph.dot

then it works. I don't understand what is the problem here.

ouboub commented 4 days ago

Hi,

First of all thanks. I just realised that dot2tex is developped also it github, therefore I will report this issue there and report back as soon as I receive some information.

ouboub commented 4 days ago

File "/usr/lib/python3.13/site-packages/dot2tex/dot2tex.py", line
3075, 

I don't see this error, but it does not work neither in my case. I opened an issue in dot2tex, github's repository

michal-h21 commented 4 days ago

Does it output some other error message? Can you run this command from the command line?

$ dot2tex --figonly --autosize -t raw -o build/complex-graph.tmp build/complex-graph.dot

Because it works for me if I run it manually.

ouboub commented 4 days ago

build/complex-graph.dot ```

Because it works for me if I run it manually.

That works for me as well!

What I meant was: if I use the modified file and run twice the command lualatex --shell-escape working-example-equation-out.tex

a pdf file generated in the build directory, without errors, but without graph as well