How to properly reference local packages in Windows?

I have created a simple local Typst package here:

C:\Users\User\AppData\Roaming\typst\packages\local\shorthand\0.1.0

Files include typst.toml:

[package]
name = "shorthand"
version = "0.1.0"
entrypoint = "main.typ"
authors = ["mikewood1980"]
license = "MIT"
description = "Shortland tools."

And a basic function definition in the main.typ file:

// main.typ

#let foo = "This is bar"

I am then testing this package on my desktop, using a new file (new.typ) in which I have tried to import this local package:

// local typst file on desktop

#import "@local/shorthand:0.1.0"

However, I am getting the following error (using Tinymist in VS Code on W10):

I appears that it knows the right location for the file, but is getting backslashes the wrong way in places, which I assume is the cause of the package not being found.

It this likely to be a mistake that I have made, a problem with Tinymist, or some other bug?

Hi there,

Your description fits GitHub - typst/packages: Packages for Typst. and I was able to reproduce it without any error on Windows 11 with Tinymist 0.13.12 installed in VSCode 1.100.2.

So to answer your question, you are properly referencing the local package in Windows, as far as you are describing.

There is no issue with the slashes or backslashes (although I agree it looks weird).

The issue is most likely the way your files are on your filesystem. Perhaps you should try to recreate your own package, let’s say shorthand2 step by step and see?

Hi there,

You seem to be going down the proper route. At least I could reproduce your setup without errors.

I wouldn’t worry too much about the mix of slashes and backslashes as Windows supports both. The output of Tinymist in VSCode contains many entries where it doesn’t cause any problems.

A few pointers:

  • I’m sure you would know but… Save everything. Reboot. :slight_smile: Reopen your files. Check the error is still present.

  • Perhaps Update VSCode and Tinymist, especially if you haven’t done so in a while?

  • You mention a file new.typ but the screenshot of the error mentions test.typ. Is that a leftover issue from a previous test or did you end up naming the files differently? Worth eliminating IMO.

  • Although it looks like it is the case, I would verify that cd %APPDATA% points to C:\Users\User\AppData\Roaming\.

  • Verify that your typst.toml file contains entrypoint = "main.typ" and not something else…

    • Note: The screenshot of the error you have provided indicates file not found but for the file typst.toml and I would have expected main.typ to show up there. This is where I would concentrate.

If it doesn’t work, perhaps you could upload your files here:

  • main.typ
  • typst.toml
  • new.typ
    and indicate your version of Tinymist and VSCode.

Finally, there is a Discord channel for Tinymist and also you could open an issue on GitHub · Where software is built if the problem persists.

EDIT: Out of curiosity, do you see your package in Tinymist like this?

Please come back with your findings!

Hi

Thanks so much for you help, and apologies for the slow response. Work is very busy at the moment!

Thank you for all your suggestions. In the end, it was quite trivial, but you were right that I should look at the location of the files more closely.

I had originally created the TOML file using ‘create new’ text document:

In Windows Explorer: > new > text document

I then saved this as typst.toml, but since windows thought I was saving a text document, it saved it as typst.toml.txt. The .txt extension was hidden in Windows Explorer, so missed that it was not formatted as TOML file. Once I changed this, the problem was solved!

Thanks again. I would not have gotten to the bottom of this so quickly without
your help.

1 Like