Here is my solution that relies on inspecting \jobname.
The source file:
% source.tex
\documentclass{article}
\usepackage{etoolbox} % for `\ifstrequal`
%% NOTE: i do not know how this works (how `\expandafter` works),
%% but it works
\newcommand{\secondVsFirstVersion}[2]{%
\expandafter\ifstrequal\expandafter{\jobname}{second-version}{#1}{#2}}
\newcommand{\mainversion}[1]{\secondVsFirstVersion{}{#1}}
\newcommand{\secondversion}[1]{\secondVsFirstVersion{#1}{}}
\begin{document}
...first simple version \secondversion{with some more comments is now second version}....
Moreover, \mainversion{this will appear only in the main version,}
\secondVsFirstVersion{this will appear only in the second version}{
and this only in the first again}.
\end{document}
To obtain the main version of the output, run
pdflatex -jobname='main-version' source.tex
(or just pdflatex source.tex).
To obtain the second, run
pdflatex -jobname='second-version' source.tex
Alternatively, create two hard links to this file called main-version.tex and second-version.tex and compile them as usual, without -jobname parameter.
IMO even better is to use a makefile with latexmk:
# Makefile
.DELETE_ON_ERROR:
.PHONY: all
all: v1 v2
.PHONY: v1
v1: main-version.pdf
.PHONY: v2
v2: second-version.pdf
main-version.pdf: source.tex
latexmk -pdf -jobname='main-version' '$<'
second-version.pdf: source.tex
latexmk -pdf -jobname='second-version' '$<'
.PHONY: mostlyclean
mostlyclean:
rm -f *.log
.PHONY: clean
clean: mostlyclean
rm -f *.aux *.out *.toc *.fdb_latexmk *.fls
.PHONY: distclean
distclean: clean
rm -f main-version.pdf second-version.pdf
Then to get both versions at once simply run make in the source directory.
\newcommand\secondversion[1]{}and in the other,\newcommand\secondversion[1]{#1}. Naturally, the 2nd version could also present#1in italics or color, or something else, if desired. – Steven B. Segletes Aug 30 '16 at 11:33\jobname. Here is what i did to have two different PDFs from the same source when debugging some inconsistent behavior: http://tex.stackexchange.com/q/325102/37291. – Alexey Aug 30 '16 at 11:55\jobname(as I did here): http://tex.stackexchange.com/a/71559/8528 – jon Aug 30 '16 at 14:54-jobnameargument topdflatex, your second version will overwrite the first version, unless you move the first version manually before compiling the second one. – Alexey Sep 03 '16 at 08:51