Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inlay hints in \included files with auxDirectory #906

Closed
jdujava opened this issue Jul 24, 2023 · 6 comments · Fixed by #909 or #913
Closed

Inlay hints in \included files with auxDirectory #906

jdujava opened this issue Jul 24, 2023 · 6 comments · Fixed by #909 or #913
Labels
bug Something isn't working

Comments

@jdujava
Copy link
Contributor

jdujava commented Jul 24, 2023

Setup of auxDirectory

Let's have (for example) the following aux_dir for latexmk

# .latexmkrc
$aux_dir = ".aux";

and corresponding configuration of auxDirectory for texlab. Diagnostics are then properly displayed, but the inlay hints are missing in the files which are sourced using \include. I will try to explain in the following example.

Info about my setup:

  • editor: neovim
  • compilation of latex: latexmk via vimtex plugin
  • setup of texlab: via nvim-lspconfig

Minimal reproducible example

Consider the directory structure

.
├── example.tex
└── files
    └── section1.tex

where the contents are

% example.tex
\documentclass[a4paper,12pt]{article}

\usepackage{graphicx}

\begin{document}

\section{Working example}

\begin{figure}[!ht]
    \centering
    \includegraphics[width=1.0\linewidth]{example-image-a}
    \caption{This is an example image.}
    \label{fig:missing}
\end{figure}

\include{files/section1}

\end{document}
% section1.tex
\section{Included section}

\begin{figure}[!ht]
    \centering
    \includegraphics[width=0.3\linewidth]{missing.png}
    \caption{This is a missing image. Leads to a warning/error.}
    \label{fig:random}
\end{figure}

What works and what doesn't

Inlay hint for the first figure is displayed (example-image-a), and also warning/error for the second figure (missing.png).
However, the inlay hint for the second one is not present. Perhaps surprisingly (at least for me), when the file section1.tex is sourced using \input instead of \include, the inlay hint is displayed.

@jdujava jdujava changed the title Inlay hints with auxDirectory for \included files Inlay hints in \included files with auxDirectory Jul 24, 2023
@pfoerster
Copy link
Member

@jdujava Thanks for the detailed report. This will be fixed with #909.

@pfoerster pfoerster added the bug Something isn't working label Jul 29, 2023
pfoerster added a commit that referenced this issue Jul 30, 2023
- Search in the same directory as well in addition to the configured aux directory
- Allow configuring aux directory independent of log directory
- Deprecate texlab.auxDirectory in favor of texlab.build.auxDirectory

Fixes #906.
@jdujava
Copy link
Contributor Author

jdujava commented Aug 3, 2023

I tried out texlab v5.8.0 with the following settings passed to LSP via nvim-lspconfig

texlab = {
    build = {
        args = {
            '-pdf',
            '-interaction=nonstopmode',
            '-synctex=1',
            '-outdir=.aux',
            '%f',
        },
        auxDirectory = '.aux',
        logDirectory = '.aux',
    }
}

In my experience, the same problem occurs as I described previously (inlay hints work with \input but not with \include).
@pfoerster Can you reproduce it, or is there anything else I should configure to make it work?

@pfoerster pfoerster reopened this Aug 5, 2023
@pfoerster
Copy link
Member

@jdujava Thanks for the update.

Can you reproduce it

No, I am no longer able to reproduce it with v5.8.0. Can you share the contents of all aux files (example.aux and section1.aux) and where they are located relative to the source files?

Also, you should not set logDirectory to .aux as the log files are still located next to the TeX files.

@jdujava
Copy link
Contributor Author

jdujava commented Aug 5, 2023

@pfoerster Thank you for looking into this!

The initial directory tree is (with the contents given in first comment of this issue)

.
├── example.tex
├── files
│   └── section1.tex
└── .latexmkrc

Compiling with latexmk (version 4.79) either with vimtex plugin or directly as

latexmk -pdf -interaction=nonstopmode -synctex=1 example.tex

results in

.
├── .aux
│   ├── example.aux
│   ├── example.fdb_latexmk
│   ├── example.fls
│   ├── example.log
│   ├── example.out
│   └── files
│       └── section1.aux
├── example.pdf
├── example.synctex.gz
├── example.tex
├── files
│   └── section1.tex
└── .latexmkrc

Since I obtained example.log in the .aux directory, only after setting logDirectory to .aux the LSP is able to process it.
I also find this behaviour preferable as it leads to a cleaner directory tree.

The contents of *.aux files are

% .aux/example.aux
\relax 
\providecommand\hyper@newdestlabel[2]{}
\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument}
\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined
\global\let\oldnewlabel\newlabel
\gdef\newlabel#1#2{\newlabelxx{#1}#2}
\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}}
\AtEndDocument{\ifx\hyper@anchor\@undefined
\let\newlabel\oldnewlabel
\fi}
\fi}
\global\let\hyper@last\relax 
\gdef\HyperFirstAtBeginDocument#1{#1}
\providecommand\HyField@AuxAddToFields[1]{}
\providecommand\HyField@AuxAddToCoFields[2]{}
\@writefile{toc}{\contentsline {section}{\numberline {1}Working example}{1}{section.1}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces This is an example image.}}{1}{figure.1}\protected@file@percent }
\newlabel{fig:missing}{{1}{1}{This is an example image}{figure.1}{}}
\@input{files/section1.aux}
\gdef \@abspage@last{2}
% .aux/files/section1.aux
\relax 
\providecommand\hyper@newdestlabel[2]{}
\@writefile{toc}{\contentsline {section}{\numberline {2}Included section}{2}{section.2}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces This is a missing image. Leads to a warning/error.}}{2}{figure.2}\protected@file@percent }
\newlabel{fig:random}{{2}{2}{This is a missing image. Leads to a warning/error}{figure.2}{}}
\@setckpt{files/section1}{
\setcounter{page}{3}
\setcounter{equation}{0}
\setcounter{enumi}{0}
\setcounter{enumii}{0}
\setcounter{enumiii}{0}
\setcounter{enumiv}{0}
\setcounter{footnote}{0}
\setcounter{mpfootnote}{0}
\setcounter{part}{0}
\setcounter{section}{2}
\setcounter{subsection}{0}
\setcounter{subsubsection}{0}
\setcounter{paragraph}{0}
\setcounter{subparagraph}{0}
\setcounter{figure}{2}
\setcounter{table}{0}
\setcounter{section@level}{1}
\setcounter{Item}{0}
\setcounter{Hfootnote}{0}
\setcounter{bookmark@seq@number}{2}
}

@pfoerster
Copy link
Member

@jdujava Thanks!

The behavior of latexmk seems to be a bit strange. Initially I had section1.aux right next to section1.tex, which is why I was not able to reproduce the issue anymore. However, both cases should be handled by #913 now. Can you give this PR a try, please?

@jdujava
Copy link
Contributor Author

jdujava commented Aug 5, 2023

I tried out #913 and everything seems to work alright 👍 , thanks @pfoerster!

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Nov 15, 2023
## [5.11.0] - 2023-11-05

### Added

- Add `texlab.inlayHints.labelDefinitions` and `texlab.inlayHints.labelReferences` options ([#753](latex-lsp/texlab#753))
- Display inlay hints for label references by default ([#753](latex-lsp/texlab#753))

### Fixed

- Moving the build logs to the recycle bin will now clear the diagnostics ([texlab-vscode/#825](latex-lsp/texlab-vscode#825))
- Fix false positive when reporting syntax errors for BibTeX accents ([#945](latex-lsp/texlab#945))

## [5.10.1] - 2023-10-10

### Fixed

- Fix regression when renaming commands ([#936](latex-lsp/texlab#936))

## [5.10.0] - 2023-09-30

### Added

- Allow passing additional arguments to `ChkTeX` using `texlab.chktex.additionalArgs` ([#927](latex-lsp/texlab#927))

### Fixed

- Fix loading bibliographies from `kpathsea` search path ([#923](latex-lsp/texlab#923))
- Don't report duplicate results when using goto definition on includes ([#924](latex-lsp/texlab#924))
- Fix project detection when there exist files with the same name ([#923](latex-lsp/texlab#923))
- Do not report parse errors with `$` in paths ([#931](latex-lsp/texlab#931))

## [5.9.2] - 2023-08-14

### Fixed

- Don't crash when using comments inside `\include`-like commands ([#919](latex-lsp/texlab#919))
- Folding ranges include only the contents instead of the entire range of the structure.
  For example, the folding range of an environment will start after the `\begin` and stop before the `\end`
  ([#915](latex-lsp/texlab#915))

## [5.9.1] - 2023-08-11

### Fixed

- Improve performance when completing BibTeX entries ([#493](latex-lsp/texlab#493))
- Don't report unused entries for very large bibliographies
- Avoid redundant reparses after saving documents

## [5.9.0] - 2023-08-06

### Added

- Use bibliographies found in `BIBINPUTS` environment variable ([#493](latex-lsp/texlab#493))
- Add `texlab.build.pdfDirectory` setting ([#911](latex-lsp/texlab#911))

### Fixed

- Fix search path for aux files when using `\include` instead of `\input` ([#906](latex-lsp/texlab#906))

## [5.8.0] - 2023-07-30

### Added

- Report diagnostics for unused and undefined labels
- Report diagnostics for unused BibTeX entries and undefined citations
- Report diagnostics for duplicate BibTeX entries
- Report diagnostics for duplicate labels
- Add `texlab.build.auxDirectory` and `texlab.build.logDirectory` settings ([#906](latex-lsp/texlab#906))

### Deprecated

- Deprecate `texlab.auxDirectory` in favor of `texlab.build.auxDirectory`

### Fixed

- Fix parsing paths with `|` ([#568](latex-lsp/texlab#568))
- Fix parsing LaTeX identifiers with `=` ([#568](latex-lsp/texlab#568))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants