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


I can write:


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


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}}


\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":


\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


% this works

% \begin{diagram}[width=0.5\textwidth] % <- what I ACTUALLY want to write
% \begin{diagram}[width=\tobp{0.5\textwidth}] % <- what I tried to do
dia = circle 1



Add \RequirePackage{graphics}

and modify according line for width (and analogously height) to:

\DeclareOptionX{width}[]{\Gin@defaultbp\foo{#1}\def\dtt@width{-w \foo}}
  • Welcome to TeX.SE! Could you please add a complete minimal working example, i.e. a short document that starts with \documentclass, ends with \end{document}, can be compiled and illustrates your point?
    – user121799
    Commented Nov 2, 2018 at 21:39

1 Answer 1


the graphics package has a command that does exactly that:


is the output from







You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .