You could use the preview
package for this. It's basically the "pure (La)TeX variant of pdfcrop
" you are looking for. You need to set the text height to \maxdimen
e.g. using geometry
and wrap every page in \begin{preview}
... \end{preview}
. To do this simply have a \begin{preview}
after \begin{document}
, a \end{preview}
before \end{document}
and define a \newpage
variant as \end{preview}\begin{preview}
. You will loose some of the border which can be readded using the \PreviewBorder
macro. However, AFAIK this doesn't support header and footer.
Here now some example code. Apparently preview
already takes care to suppress automatic page breaks and the modification of the text height is not required.
\documentclass{article}
\usepackage[active,tightpage]{preview}
\renewcommand{\PreviewBorder}{1in}
\newcommand{\Newpage}{\end{preview}\begin{preview}}
\usepackage{lipsum}
\begin{document}
\begin{preview}
\lipsum
\Newpage
\lipsum[1]
\Newpage
\lipsum[1-30]
\Newpage
\lipsum[4-22]
\end{preview}
\end{document}
I made a little script using the built in tools of Windows, so you don't have to install a thing. It is basically recursively scanning the source
directory for pdf
files and then copying them in the destination
folder.
I work with TeXStudio, that is a different version of Texmaker. However, I think that you can run the script within the IDE in the same way. In the quickbuild
part there should be an option for a user command there you can write your own compilation, for example for pdflatex
:
pdflatex -shell-escape -synctex=1 -interaction=nonstopmode %.tex | tmx://internal-pdf-viewer | "C:\LaTeX Projects\move-pdf.bat" . pdfs
In this case, you need the absolute path of the script, and also you will need to input the directories.
To execute the script manually, you need to call it in a command line: move-pdf.bat source destination
(assuming that you named the script move-pdf.bat
). For example if you want to run it in your current directory just execute: move-pdf.bat . pdfs
. If you want to run it in several directories it is a good idea to put it in a place where your system can find it, or add the path where you place the script to the system variables. Else, you can place it in every directory. Moreover, if you want to avoid passing the parameters all the time and just to execute for a default source and destination, put those paths in the two variables src
and dst
.
@ECHO off
IF [%1]==[] GOTO usage
IF [%2]==[] GOTO usage
SET src=%~f1
SET dst=%~f2
IF EXIST "%dst%" GOTO process
MKDIR "%dst%"
:process
ECHO Copying from "%src%" to "%dst%"
:: Exclude file. Exclude the same directory in the case that destination is a subdir of source.
SET exf=%TEMP%\%~n0-exclude.txt
echo %dst% > %exf%
:: Move to source
SET cur=cd
cd "%src%"
:: Copy files recursively (/S), and only newer than destination (/D), automatically (/Y).
FOR /R %%G IN (*.pdf) DO XCOPY /S /D /Y /EXCLUDE:%exf% "%%G" "%dst%"
:: Return to original
cd "%cur%"
:clean
del "%exf%"
GOTO end
:usage
ECHO Usage: %0 source destination
ECHO If destination does not exist, it will be created.
ECHO.
:end
Best Answer
I would recommend you use the
varwidth
package which is similar to theminipage
environment, but sets its width to match the narrower natural width based on the content.This can be used either with the
standalone
package, or you can directly use thepreview
package to get (note that the border shown here is from my image capturing):Here is the MWE using the
standalone
class:and using the
preview
package:I suspect that
standalone
class internally uses thepreview
package to do something like this, so probably not much difference in this case, but might be useful if you needed to use a different class.If this is something you are going to do often it is worthwhile automating this solution by using
\AtBeginDocument
and\AtEndDocument
in the preamble to automate this. Here is the same code with this automation in the preamble and using thebook
class: