Edit. My question can be reworded as: "How can I check, by command line, if different sources generate exacty the same .pdf layout?"
I'm improving some emacs scripts of mine that I wrote to remove comments and/or unused macros from the source .tex file.
Here's a sample or my code:
(save-buffer)
(call-process-shell-command
(concat "latex \"\\let\\oldExecuteOptions\\ExecuteOptions\"\\\n"
"\"\\def\\ExecuteOptions#1{\\oldExecuteOptions{#1,draft}}\"\\\n"
"\"\\nonstopmode\\input{" (buffer-name) "}\";"
"mv " (file-name-sans-extension (buffer-name)) ".pdf /tmp/" ) nil nil)
;;; =========================================================================
;;; =========================== "COMMENT" AMBIENT ===========================
;;; =========================================================================
;;The "comment" ambient is defined in the "verbatim" e "comment packages"
(if (string-match-p "\\\\includecomment[\s\t\n]*{comment}" (buffer-string))
(read-string "SOME WARNING HERE...")
;; *ELSE*
(progn
(goto-char (point-min))
(while (search-forward-regexp "\\\\begin[\s\t\n]*{comment}" nil t)
(save-excursion
(let ((b (make-marker))
(e (make-marker)))
(set-marker b (match-beginning 0))
(search-forward-regexp "\\\\end[\s\t\n]*{comment}" nil t)
(set-marker e (point))
(goto-char b)
(unless (nth 4 (syntax-ppss))
(comment-region b e))
)))
(save-buffer)
(call-process-shell-command
(concat "latex \"\\let\\oldExecuteOptions\\ExecuteOptions\"\\\n"
"\"\\def\\ExecuteOptions#1{\\oldExecuteOptions{#1,draft}}\"\\\n"
"\"\\nonstopmode\\input{" (buffer-name) "}\"" ) nil nil)
)
)
As can be seen:
- I first compile my source by passing the
draftoption by command line, saving/moving my output in the/tmp/directory. - Then I "comment" (with
%) and remove the "comment" ambients from the source.texfile. - Finally I compile my
cleanedsource, again with thedraftoption...
So I first have:
\documentclass[11pt]{article}
\pdfoutput=1
\usepackage{comment}
\usepackage{blindtext}
\pagestyle{empty}
\begin{document}
\blindtext
\begin{comment}
\blindtext
\end{comment}
\end{document}
and then
\documentclass[11pt]{article}
\pdfoutput=1
\usepackage{comment}
\usepackage{blindtext}
\pagestyle{empty}
\begin{document}
\blindtext
\end{document}
My question is: "How can I check by command line, if the layout has (or not) changed?".
I tried to compare the two pdfs by command line:
cmp mydoc.pdf /tmp/mydoc.pdf
but it always says that the files are different. But I know the layout has unchanged.
If I try with diffpdf (a GUI program) it says "the pdfs appear to be the same" but, as I said, I need a command line solution. I mean I need to get the comparison result in the stdout of my terminal so I can use it in my scripts (e.g. with the emacs' shell-command-to-string fuction). I do not need (and I don't want) to visual check the layout in this stage.
Please, let me know if I've been able to explain my purpose in a clear way.
NOTE. This is a dummy example but in some cases could be tricky to check if some changes will affect the layout.
My considerations. After many attempts using a "file content" approach (I tried a
faketimecommand approach (see here) but it works only with small and simple files) I'm convinced that I need a "layout approach". A tool likediffpdf(with the--appearanceoption) that could echo in thestdoutcould be the solution.
layoutitself. The content of the document has changed and you can check this difference by something simple like amd5sumhash or similar programs or\pdfmdfivesumfrom withinpdflatexitself. If there's a single white space character more or less than before the md5 hash sums will differ – Aug 06 '17 at 23:17dvifile is related to the system clock. If I compile a file at 9:03 and then I compile again the same file at 9:04... I will get two different hashcodes. I suppose that the same happens with the pdflatex compiler but with a littler time interval. – Gabriele Aug 07 '17 at 07:07SOURCE_DATE_EPOCHand related subjects in the pdftex documentation. – Ulrike Fischer Aug 07 '17 at 07:21