0

My question is mostly trying to troubleshoot why I get different results in VSCode vs Overleaf. When I paste this code into Overleaf vs VSCode/LaTeX Workshop I get different results. The code comes from a previous answer about updating headers based on levels of page content.

In Overleaf pages 3-4 of the results have a "Level 3" header, as they should because the Level 3 paragraph runs from page 3 to page 4.

In VSCode the page 4 header does not carry forward the "Level 3" from the paragraph spanning pages, and instead uses the highest from page 4 which is "Level 2" header.

Overleaf: This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021)

VSCode: This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2022/dev)

MWE

\documentclass{article}

\usepackage{afterpage} \usepackage{lipsum} \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{}

\newcounter{pagelevel} \newcounter{currentlevel}

\usepackage{atbegshi} \usepackage{zref-user} \usepackage{zref-abspage}

\newcounter{clscnt} \makeatletter % When we ship out the page, check if the paragraph spans the break. \AtBeginShipout{% \ifnum\zref@extract{markingenv-begin-\theclscnt}{abspage} =\zref@extract{markingenv-end-\theclscnt}{abspage} \setcounter{pagelevel}{0}% \else \setcounter{pagelevel}{\thecurrentlevel}% \fi } \makeatother

\newcommand{\marking}[2]{% \stepcounter{clscnt}% \zlabel{markingenv-begin-\theclscnt}% (#1 --- \thepagelevel) \ifnum #1 > \thepagelevel% \setcounter{pagelevel}{#1}% \chead{Level \thepagelevel}% \fi% \setcounter{currentlevel}{#1} #2 \zlabel{markingenv-end-\theclscnt}% }

\newcommand{\VI}[1]{\marking{3}{(V) #1}} \newcommand{\IMP}[1]{\marking{2}{(I) #1}} \newcommand{\TRI}[1]{\marking{1}{(U) #1}}

\begin{document} \TRI{\lipsum[1]\par} \TRI{\lipsum[2]\par} \TRI{\lipsum[3]\par} \IMP{\lipsum[4]\par} \TRI{\lipsum[5]\par} \TRI{\lipsum[6]\par} \TRI{\lipsum[7]\par} \TRI{\lipsum[8]\par} \IMP{\lipsum[9]\par} \TRI{\lipsum[10]\par} \TRI{\lipsum[11]\par} \TRI{\lipsum[12]\par} \TRI{\lipsum[13]\par} \TRI{\lipsum[14]\par} \TRI{\lipsum[15]\par} \VI{\lipsum[16]\par} \IMP{\lipsum[17]\par} \TRI{\lipsum[18]\par} \TRI{\lipsum[19]\par} \TRI{\lipsum[20]\par} \TRI{\lipsum[21]\par} \TRI{\lipsum[22]\par} \TRI{\lipsum[23]\par} \TRI{\lipsum[24]\par} \TRI{\lipsum[25]\par} \TRI{\lipsum[26]\par} \TRI{\lipsum[27]\par} \TRI{\lipsum[28]\par} \TRI{\lipsum[29]\par} \end{document}

Overleaf Results

Overleaf Results

VSCode Results

VS Code Results

Paul Gessler
  • 29,607
Drew M.
  • 15
  • 3
    It matters little with your editor such as VS Code. It is advised to tell us your LaTeX compiler version and your flavour of LaTeX (i.e. pdfLaTeX, XeLaTeX, LuaLaTeX, etc.) on Overleaf and your PC. – Teddy van Jerry Apr 05 '22 at 19:04
  • @TeddyvanJerry LaTeX Versions: Overleaf: This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021) VSCode: This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2022/dev) and VSCode March 2022 (version 1.66) with LaTeX Workshop v8.24.1 – Drew M. Apr 05 '22 at 19:11
  • 1
    Well, if you look into the log information, you will find you have to compile it twice. (LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.) You did it only once while Overleaf cleverly did it twice (something like latexmk). – Teddy van Jerry Apr 05 '22 at 19:17
  • I've run latexmk on it twice and I still get the error Label(s) may have changed. Rerun to get cross-references right. and the header for the overrun page still shows "Level 2". Oddly enough, in Overleaf it doesn't matter if I run pdfTeX or LuaTex, the results are always correct. In VSCode the results are always wrong no matter which engine I use. – Drew M. Apr 05 '22 at 19:26
  • 1
    My latexmk (which calls pdflatex) works out fine with TeX Live 2021 and running pdflatex twice is also okay. – Teddy van Jerry Apr 05 '22 at 19:29
  • I wasn't adding -pdf, thanks for that edit, that seems to work! – Drew M. Apr 05 '22 at 19:29

1 Answers1

1

This is a matter of label update. Your code requires knowledge of the page so it will not work properly with only one run. So if you look into the log information, you will find it tells you

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

So you need to compile it the second time and then the results of the VS Code and Overleaf are the same. Overleaf did it cleverly by using latexmk, which is also a convenient way for you to do with VS Code if you do not want to carefully choose how many times to run LaTeX, BibTeX or Biber. Using latexmk is also very convenient with LaTeX-Workshop extension in VS Code. (Remeber to add the -pdf option).