0

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}
2
  • See ctan.org/topic/subdocs . Probaply yoy want to use docmute or standalone, and may be subfiles if you have a complex working directory.
    – Fran
    May 27, 2019 at 19:19
  • Welcome to tex.sx. This looks like a candidate for \include and \includeonly if you want to process and look at individual sections. May 27, 2019 at 19:19

1 Answer 1

1

Posting OP‘s answer that was formerly inside the question, now here as a community wiki:

Now I can use preview-latex in emacs outside of main.tex. I can still use main.tex to compile .pdf, but at the same time in linked file (a.tex in my example) I can use fast preview-latex (C-c C-p C-p) to check on tikzpicture.

I also removed all previous clutter, no need for it any more, I think.

No idea how to upvote answers I got. but it was Fran's answer about docmute package that worked. Not tested, but I guess my linked (\input) files will not have to have its preamble updated beyond what is needed for tikzpicture in my case.

Please someone, enlighten me how to upvote those answers I got.

main.tex

\documentclass{book}
%\usepackage{standalone}
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.misc}
%\usepackage[active,float]{preview}
%\PreviewEnvironment{tikzpicture} 
\usepackage{docmute}
\begin{document}
\input{a.tex}
\end{document}

a.tex

\documentclass{book}
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.misc}
\usepackage[active,float]{preview}
\PreviewEnvironment{tikzpicture} 

\begin{document}
\section{some}
some text
some more text
\begin{tikzpicture}[my shape/.style={
rectangle split, rectangle split parts=#1, draw, anchor=center}]
\node [my shape=5] at (0,1)
{abcdetghijkl\nodepart{two}b\nodepart{three}c\nodepart{four}d\nodepart{five}e};
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .