2

In my LaTeX document I am using the following structure: I have a main tex-file from which chapters are included via include(.). Thus, each chapter has its own tex-file.

For some time now, I encountered synchronization problems between my source and the PDF viewer, i. e., the "go to PDF" and "go to source" of my IDE do not work. Weird enough, I only have this issue with some of the chapters. In my chapter's file names, I do neither use special characters nor spaces. Since this issue bothered me some time now, I tried to narrow it down.

The cause is apparently that synctex does not like the trim = ..., clip option of \includegraphics. Issues of such kind were already reported here and here. In the latter post this issue is already attributed to the clip option. However, I believe I can even further describe the bug (I don't think it is a feature) and therefore hope a solution or workaround to be around.

Here comes a MWE:

main.tex

\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}

\begin{document}

\author{TeXstudio Team}
\title{Simple Book Example}
\date{January 2013}

\frontmatter
\maketitle
\tableofcontents

\mainmatter
\include{./chapter01}
\include{./chapter02}

\backmatter
% bibliography, glossary and index would go here.

\end{document}

chapter01.tex

\chapter{The First Chapter}

\begin{figure}[h]
    \includegraphics[trim=0 0 0 0,clip,
    width=0.8\textwidth]{./test.jpg}
\end{figure}

\begin{figure}[h]
    \includegraphics[trim=0 0 0 0,clip, % can also be 'clip' without 'trim = ...'
    width=0.8\textwidth]{./test.jpg}
\end{figure} 

chapter02.tex

\chapter{The Second Chapter}

Here is some text!

From within chapter02.tex you should not be able to sync to our PDF viewer and vice versa due to the clip option in the proceeding \include{.} (also fails to sync when code of chapter01.tex is placed in main.tex; but syncs when code of both chapters are placed in main).

Now comes the interesting bit: just remove or comment trim=0 0 0 0,clip, in the second figure's \includegraphics (and only there) and the synchronization should work (if the two figures are printed on individual pages). That is, it works even though the first figure's option is still trim=0 0 0 0,clip,.

Therefore, it looks like the clip option causes only problems when the corresponding figure is displayed in the PDF on the last page, i. e., directly proceeding the following include for which the syncing fails. You may also put text around the figure to avoid the figure being printed on the chapter's last page and then syncing should also work fine.

Neither \clearpage nor empty includes (\include{}) before the chapters' includes work for me.

So, currently I just do not use the clip option for figures at the end of chapters. And even though I would want to avoid figures at the end of chapters in my final version anyway (some style guides advice against it), a working solution would still be appreciated very much!

  • that seems odd, it probably depends on the pdf viewer, which are you using? trim=0 0 0 0,clip, doesn't actually do anything does your real use have non zero values? – David Carlisle May 28 '16 at 21:18
  • As I wrote in the comment of the MWE, even without trim and only clip the syncing fails. Can you reproduce the bug? – ToJo May 28 '16 at 21:22
  • I don't have reverse search set up anyway, but as I said you probably need to say which viewer you are using. but again clip shouldn't be needed (or do anything) unless you are changing the bounding box of your figures – David Carlisle May 28 '16 at 21:53
  • @DavidCarlisle I can reproduce using Kile and Okular for backwards search. (But only backwards. Forward search seems to work OK from the main file. Forward search doesn't work generally from the included files with my current set-up, so I can't test that.) For backwards search, it searches for a file with the name of the working directory i.e. it loses the last part of the path consisting of the file name and extension. – cfr May 28 '16 at 22:04
  • @DavidCarlisle I can reproduce this error with TeXstudio for both the internal as well as external viewer (Sumatra) and in both directions (forward and backwards). Sumatra's output for forward search, i. e., "go to PDF", is "unknown file 'chapter02.tex'", for backward sync it is "no sync information available". – ToJo May 29 '16 at 12:40

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.