1

I've two *.tex documents, a main one and another one included in main.

main.tex:

\documentclass{article}
\begin{document}
\section{Hello}
\begin{equation}
  \label{eq:1}
  \frac{1}{9000}
\end{equation}
\include{./stuff}
\end{document}

stuff.tex:

Hallo

\begin{equation}
  \label{eq:2}
  \frac{1}{2}
\end{equation}

This is the second equation \ref{eq:2}

How can I preview only the second one when open in Emacs? When I try to generate the buffer preview (C-c C-p C-b) i get the following error:

Running `Preview-LaTeX' on `_region_' with ``pdflatex   "\nonstopmode\nofiles\PassOptionsToPackage{active,tightpage,auctex}{preview}\AtBeginDocument{\ifx\ifPreview\undefined\RequirePackage[displaymath,floats,graphics,textmath,sections,footnotes]{preview}[2004/11/05]\fi}" "\input" _region_.tex''
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, lo
aded.

No auxiliary output files.

(./_region_.tex  !name(stuff.tex)  !name(stuff.tex) !offset(-2) 

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.3 H
     allo

Overfull \hbox (20.0pt too wide) in paragraph at lines 3--4
[] 

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.5 \begin{equation}


Overfull \hbox (20.0pt too wide) in paragraph at lines 5--5
[] 

Overfull \hbox (7.40001pt too wide) detected at line 8
[][]

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.10 T
      his is an equation \ref{eq:2}
! Undefined control sequence.
<write> ...ing: Reference `eq:2' on page \thepage 
                                                  \space undefined\on@line .
l.10 This is an equation \ref{eq:2}


LaTeX Warning: Reference `eq:2' on page  undefined on input line 10.


Overfull \hbox (20.0pt too wide) in paragraph at lines 10--11
[]

Overfull \hbox (10.86105pt too wide) in paragraph at lines 10--11
[] 

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.12 $
      \frac{2}{5}$

Overfull \hbox (26.38612pt too wide) in paragraph at lines 12--14
[]$[]$
 !name(stuff.tex) !offset(-15) )
! Emergency stop.
<*> ...review}[2004/11/05]\fi} \input _region_.tex

!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on _region_.log.

TeX Output exited as expected with code 1 at Mon Mar  9 21:44:23
LaTeX: LaTeX found no preview images

Generating the preview from the main one and creating a pdf from terminal with pdflatex main.tex works fine. I've allready googled a bit and probably it's something very basic, but couldn't find what's missing. Thanks!

UPDATE 1:

As pointed out by giordano, i have to set the master file. http://www.gnu.org/software/auctex/manual/auctex/Multifile.html#Multifile

Now the small 2 files example works fine with the exception of references, but the real document I'm working with has other issues despite having the same structure.

The main problem seems to be that it is not recognizing an \end{figure} command (C-c C-c and compiling from terminal work both fine).

! LaTeX Error: \begin{figure} on input line 448 ended by \end{document}.
...
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on _region_.log.
...
Current allocation mode is local
Last OS error: No such file or directory
Current file position is 1935
GPL Ghostscript 9.05: Unrecoverable error, exit code 1

Preview-PDF2DSC exited abnormally with code 1 at Tue Mar 10 13:08:59

As workaround I've found the preview package with the option displaymath to see equations. http://www.gnu.org/software/auctex/manual/preview-latex.pdf

I'll leave the question 2-3 days open and if there is no other answer for Auctex getting crazy I'll close it then.

  • 1
    Setting the master file in the secondary file (issue C-c C-_) definitely helps, running C-c C-c to build the whole document before trying to preview seems to be also useful. – giordano Mar 9 '15 at 21:59
  • Try also issuing C-c C-p C-d (bound to preview-document), this will preview the whole document, including secondary files. No C-c C-c needed here. – giordano Mar 9 '15 at 22:08
  • @giordano Yes, setting the master file is a good idea. Despite it I still have other problems, see update. – Gypaets Mar 10 '15 at 12:29
  • \ref{} aren't intended to be previewed and I cannot reproduce a problem with a \begin{figure}...\end{figure}. I get the error \begin{figure} on input line NNN ended by \end{document}. if I delete or comment the \end{figure} line. – giordano Mar 10 '15 at 12:33

Your Answer

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

Browse other questions tagged or ask your own question.