I am using Fedora30 and Emacs26.2 in i3wm, TeX 3.14159265 (TeX Live 2018), and AucTex v12.1. I am working on large project (book), and will create quite a few .tex files. Question. Is it possible to use preview-latex outside of main.tex file in which I link sections belonging to chapters. Preview-latex works in main.tex but not in linked section.tex file.
Main.tex looks something like:
\documentclass[a4paper, 11pt, twoside, openright, ]{book}
\title{Title}
\usepackage{import}
\usepackage{makeidx}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{parskip}
\usepackage{tikz}
%following 2 lines allow preview-latex for tikz in main.tex
%https://tex.stackexchange.com/questions/28564/tikzpicture-blank-in-preview#40461
\usepackage[active,float]{preview}
\PreviewEnvironment{tikzpicture}
\makeindex
\begin{document}
\maketitle
\frontmatter
\import{./}{title.tex}
\clearpage
\thispagestyle{empty}
\tableofcontents{}
\mainmatter
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\markboth{Introduction}{}
\import{sections/}{intro.1.tex}
\chapter{chapter1}
\import{sections/}{ch01.section1.tex}
\backmatter
\end{document}
In ch01.section1.tex file in my case I have for example:
\section{some-text}
text...text...text...
\begin{tikzpicture}
\draw[gray, thick] (-1,2) -- (2,-4);
\draw[gray, thick] (-1,-1) -- (2,2);
\filldraw[black] (0,0) circle (2pt) node[anchor=west] {Intersection point};
\end{tikzpicture}
By moving that chapter to main.tex I can confirm that I can use preview-latex on tikz code (thanks to tikzpicture blank in preview), although I get dark background (due to my emacs background I guess) preview of drawing. However, I am not able to get any kind of preview when trying it against ch01.section.tex file.
I should add that I was not able to produce any preview-latex in separate file. Not only tikzpicture but also \section and \subsection are not previewed.
Errors I was getting when trying preview-latex against ch.01.section1.tex separate file were not surprisingly "LaTeX Error: Missing \begin{document}"
Does anyone knows how to enable preview-latex in separate .tex files.
EDIT: Well, after trying barbara's answer although knowing it has to do with document structure and not with my problem and playing with it, I accidentally found following. I can get preview-latex in separate chapter file by running for example C-c C-p C-p from main.tex file. It does not really matter where from in main.tex I execute this command (preview at point) it will show preview in both, main.tex and chapter.tex. In order to remove preview from both files I have to issue commands in both windows. That works regardless if I use \include or \import.
One more thing. I had to remove
\usepackage[active,float]{preview}
from main.tex because I was getting strange results with that one active.
Although I got to see what I was after (preview-latex in separate file) I will still wait a bit before closing this question. Maybe (hopefully) someone has better way of acheiving this.
EDIT2 I forgot to add that I had to change ch01.section1.tex and add \begin{figure} and \end{figure} in order to get preview-latex display in ch01.section1.tex file
\begin{figure}
\begin{tikzpicture}
\draw[gray, thick] (-1,2) -- (2,-4);
\draw[gray, thick] (-1,-1) -- (2,2);
\filldraw[black] (0,0) circle (2pt) node[anchor=west] {Intersection point};
\end{tikzpicture}
\end{figure}
docmuteor standalone, and may besubfilesif you have a complex working directory. – Fran May 27 '19 at 19:19\includeand\includeonlyif you want to process and look at individual sections. – barbara beeton May 27 '19 at 19:19