I am trying and failing to adapt diagrams-latex.sty to do what I want. It takes optional parameters width and height that are passed on to an external script, but wants them as a dimensionless value that is semantically interpreted as bp. I would like to change the enviroment in a way that instead of
\begin{diagram}[width=100]
...
\end{diagram}
I can write:
\begin{diagram}[width=0.5\textwidth]
...
\end{diagram}
and the value is converted to bp behind the scenes and passed on to the external script as argument.
I managed to get a conversion function by adapting this answer, by defining
\usepackage{pgfmath}
\newcommand\tobp[1]{\pgfmathsetmacro\len{#1/1bp}\len{}}
and \tobp results in a dimensionless number, as I wanted to and it works when printing the resulting number into the document. But I can not call it in the parameter list like [width=\tobp{...}] and I also can not use it to wrap the argument in diagrams-latex.sty. I tried things like changing
\DeclareOptionX{width}[]{\def\dtt@width{-w #1}}
to
\DeclareOptionX{width}[]{\def\dtt@width{-w \tobp{#1}}}
but whatever I do, I get all kinds of error messages like
Incomplete \iffalse; all text was ignored after line 61.
How is what I want done properly?
Thanks a lot in advance!
"Minimal working example":
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage[backend=pgf, extension=pgf, outputdir=diagrams, input, cmdprefix={stack exec --}]{diagrams-latex}
% this seems to convert any unit to unitless number which is in bp
\usepackage{pgfmath}
\newcommand\tobp[1]{\pgfmathsetmacro\len{#1/1bp}\len{}}
\begin{document}
% this works
\tobp{\textwidth}
\tobp{10em}
\tobp{100pt}
% \begin{diagram}[width=0.5\textwidth] % <- what I ACTUALLY want to write
% \begin{diagram}[width=\tobp{0.5\textwidth}] % <- what I tried to do
\begin{diagram}[width=100]
dia = circle 1
\end{diagram}
\end{document}
Solution:
Add \RequirePackage{graphics}
and modify according line for width (and analogously height) to:
\DeclareOptionX{width}[]{\Gin@defaultbp\foo{#1}\def\dtt@width{-w \foo}}
\documentclass, ends with\end{document}, can be compiled and illustrates your point? – Nov 02 '18 at 21:39