0

I am trying to store the figure height and width into a separate file, for this I write the code (please excuse me, if these are not in a standard method) as below:

\documentclass{book}


\RequirePackage{color,graphicx}%
\RequirePackage{printlen}%

\uselengthunit{cm}

\newlength\imageheight
\newlength\imagewidth

\newwrite\imgdetail%
\immediate\openout\imgdetail\jobname.imd%

\let\LTXincludegraphics\includegraphics%

\newbox\fightbox%
\newdimen\fightdimen%

\newcount\fightcounter%

\def\fightvalue{}%

\renewcommand\includegraphics[2][]{%
\settoheight\imageheight{\hbox{\LTXincludegraphics[#1]{#2}}}%
\fightdimen=\ht\fightbox%
\gdef\fightvalue{\strip@pt\fightdimen}%
  \write\imgdetail{\figurename\space\thefigure, Page \thepage, #2}%
  \write\imgdetail{height=\printlength{\imageheight}}%
  \LTXincludegraphics[#1]{#2}%
}%

\begin{document}

\begin{figure}
\includegraphics[draft]{gr1.eps}
\end{figure}

\end{document}

Everything works fine, but the figure height doesn't come correct, the output was:

Figure 0, Page 1, gr1.eps
height=\def cm{pt}0.0pt

Can you advise what I did wrong in this?

  • First of always post full minimal examples that others can just copy and test as is. Here we have to add a lot of code to even figure out what yours does. – daleif Jul 2 '19 at 9:46
  • @daleif Updated now... – MadyYuvi Jul 2 '19 at 9:52
  • 1
    Use \immediate\write else the writing is delayed to page shipout (???) and this gets confusing when paired with a float – daleif Jul 2 '19 at 10:33
  • @daleif Yes, your suggestion works in a good manner, now the output came as height=\def cm{pt}140.525pt, just the text \def cm{pt} doesn't need, how can I fix this? – MadyYuvi Jul 2 '19 at 10:43
  • You should not use \printlength to write to disk, it is for formatting and printing to the PDF, you'll need to figure something else out, sorry cannot help you on that one. Why do you need this anyway? (the logging of the images? ) – daleif Jul 2 '19 at 10:47