Skip to content

Could not find definition for commands in workspace files #407

@maxchang3

Description

@maxchang3

Bug Report

Disable all the other extensions except for LaTeX Workshop and LaTeX Utilities, and check that you still see this issue.

You still see this issue?: Yes

Issue

The extension fails to locate definitions for custom commands declared in .cls files located in the same directory. However, these commands resolve correctly when texdef is executed manually.

To Reproduce

Reproduction repository: texdef-fontspec-repro

Say we have a \newcommand{\testcommand}[1]{\textbf{#1}} in test20250425.cls, and a test.tex below:

% test.tex
\documentclass{test20250425}
\begin{document}
\section{Introduction}

This is a test document to check the functionality of the LaTeX template.

\testcommand{123}

\end{document}

Case 1: .cls File in the Same Directory

  1. Open test.tex, which uses a local class file test20250425.cls that defines \testcommand.

  2. Trigger "Go to Definition" on \testcommand{123} (Command + Click / Ctrl + Click)

  3. Observe the error: Could not find definition for \testcommand.

  4. Verify the command works manually using texdef:

    texdef --source --Find --tex latex --class test20250425 \testcommand

    Expected output:

    % /path/to/test20250425.cls, line 15:
    \newcommand{\testcommand}[1]{\textbf{#1}}
    

Case 2: Packages That Require XeLaTeX

  1. Edit test20250425.cls and uncomment the following lines:

    \RequirePackage{fontspec}
    \setmainfont{Times New Roman}
  2. Trigger "Go to Definition" again. The same error persists.

  3. Run the texdef command manually, which fails with:

    texdef --source --Find --tex latex --class test20250425 \testcommand

    Output:

    Compile error: Fatal Package fontspec Error: The fontspec package requires either XeTeX or...
    
  4. Change the engine to xelatex and rerun the command. This time it succeeds:

    texdef --source --Find --tex xelatex --class test20250425 \testcommand

    Output:

    % /path/to/test20250425.cls, line 15:
    \newcommand{\testcommand}[1]{\textbf{#1}}
    

Expected Behavior

The extension should correctly resolve macros defined in local .cls files and either allow users to configure the TeX engine used by texdef, or automatically detect the appropriate one based on the project context.

Logs

LaTeX Utilities Output
[00:20:12] Initializing LaTeX Utilities.
[00:20:12] Completion Watcher Initialised
[00:20:12] LaTeX Utilities Started
[00:20:12] withTelemetry: onDidChangeActiveTextEditor_tex_wordcounter
[00:20:12] TexCount args: -merge,-brief
[00:20:12] LaTeX Utilities version: 0.4.13
[00:20:13] TeXCount output for word: 14+1+0 (1/0/0/0) File: test.tex

[00:20:13] TexCount args: -merge,-brief,-char
[00:20:14] TeXCount output for char: 63+12+0 (1/0/0/0) File: test.tex

[00:20:17] Running command texdef --source --Find --tex latex --class test20250425 \testcommand
[00:20:19] Could not find definition for \testcommand
[00:20:21] withTelemetry: onDidChangeActiveTextEditor_tex_wordcounter

Desktop

  • OS: Windows 10 / MacOS (both tested)
  • VS Code version: 1.99.3
  • Extension version: 0.4.14
texdef: Version 1.10 -- 2025/02/17

Additional context

Preview

before.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions