2

A program I am using spits out LaTeX tables in LaTeX files (outreg2 command from Stata), which I run using texify to make pdfs of the tables. I crop these tables (using pdfcrop) and embed them elsewhere. However, the pdfs include page numbers, which prevent pdfcrop from cropping directly around the table. I need an automatic way to remove the page numbers before cropping. I want to insert the command \pagenumbers{gobble} into the LaTeX code to automatically remove the page numbers.

I believe

texify --pdf --texinfo="\pagenumbering{gobble}" filename.tex

should work. It does not. No exception pops up, but the page number remains. I cannot find documentation anywhere showing examples of using the --texinfo option to splice LaTeX code into the file before running the LaTeX file to create a pdf.

How should I properly use the texify command? Or is there another way to splice in \pagenumbering{gobble} before running texify?

0

2 Answers 2

5

This post contains a Stata tag and mentions the Stata user-written command outreg2 (available running ssc install outreg2). Therefore, I offer two Stata-based solutions.

Solution 1.

The outreg2 command, outputs LaTeX code that can be compiled with appropriate software. The original poster mentions

I want to insert the command \pagenumbers{gobble} into the LaTeX code to automatically remove the page numbers.

If that is all that is needed then I show below a complete example that uses filefilter to accomplish that.

clear all
set more off

* Example data, estimation and LaTeX code
sysuse auto

local filepath "/path/to/myfile.tex"

regress mpg foreign weight
outreg2 using "`filepath'", tex replace

* Introduce required text
filefilter "`filepath'" "`filepath'.2", ///
    from("\BSbegin{document}") ///
    to("\BSpagenumbering{gobble}\n\BSbegin{document}") replace

copy "`filepath'.2" "`filepath'", replace
erase "`filepath'.2"

The command filefilter just looks for

\begin{document} 

in the generated .tex file and substitutes it for

\pagenumbers{gobble}
\begin{document}

Run help filefilter for details.

Solution 2.

Use the tex(frag) option with the outreg2 command. This outputs a tex fragment that can be included in some template .tex file using the LaTeX \input{} command.

So use

outreg2 using "`filepath'", tex(frag) replace

and create a template .tex file along the lines of

\documentclass[]{article}
\setlength{\pdfpagewidth}{8.5in} \setlength{\pdfpageheight}{11in}
\pagenumbering{gobble}
\begin{document}

\input{file-created-with-outreg2}

\end{document}

This way, you can even create several tex fragments and include them all in the template .tex file.

Run help outreg2 for details.

1

Roberto answered specifically for the situation of the OP. I want to try to give a more general answer:

(For impatient readers: solution in lower part of this answer.)

First let’s create a small testfile – testfile.tex

\documentclass{article}
\begin{document}
content
\end{document}

As the OP noted, does

texify --pdf --texinfo="\pagestyle{empty}" testfile.tex:

not produce any error, but the page number is still visible (I prefer \pagestyle…). Since Texify with the option --pdf calls internally PDFLaTeX, let’s see, what does happen with

pdflatex testfile.tex "\pagestyle{empty}"

The (not so) surprising answer is: Same result – no error, but also no success. But for (PDF(La))TeX another approach is well known:

pdflatex "\pagestyle{empty}\input{testfile.tex}"

Though, oops, no change. But this one works:

pdflatex "\AtBeginDocument{\pagestyle{empty}}\input{testfile.tex}" (*)

If we try now to adapt this to Texify, we will with

texify --pdf --texinfo="\AtBeginDocument{\pagestyle{empty}}\input{testfile.tex}"

get an error texify: Missing file argument. So I tried

texify --pdf --texinfo="\AtBeginDocument{\pagestyle{empty}}\input{testfile.tex}" testfile.tex

(yes, the file is invoked twice). Surprisingly no error, but still no success. But there’s another possible parameter (cf. http://docs.miktex.org/manual/texify.html) --tex-option, and with this replacing --texinfo I found …

The solution

If a simple PDFLaTeX call as in (*) really is not enough and one wants to call Texify instead, this command prompt call works:

texify --pdf --tex-option="\AtBeginDocument{\pagestyle{empty}}\input{testfile.tex}" testfile.tex

Once again: Yes, the file is intentionally invoked twice here.

Because this is rather long, one could put this in a batch file and later call this instead.

test.bat:

@echo off

texify --pdf --tex-option="\AtBeginDocument{\pagestyle{empty}}\input{%1}" %1

Now in command prompt one has to execute:

test.bat testfile.tex

At least it worked fine here in this way.


BTW: Thanks to Werner, because he brought up \AtBeginDocument… in his comment to the duplicate question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.