Former question: Autoloading and adding code to a package in the user init.m

I am using MaTeX, and I found the updateMaTeX[] function] at the GitHub repo. I tried to add this to my init.m in the MaTeX` context, and wrote

updateMaTeX[] :=
  Module[{json, download, target},
      json = Import["https://api.github.com/repos/szhorvat/MaTeX/releases/latest", "JSON"];
      download = Lookup[First@Lookup[json, "assets"], "browser_download_url"];
      target = FileNameJoin[{CreateDirectory[], "MaTeX.paclet"}];
        PrintTemporary@Labeled[ProgressIndicator[Appearance -> "Necklace"], "Downloading...", Right],
      ]; URLSave[download, target],
    ]; If[FileExistsQ[target], PacletManager`PacletInstall[target], $Failed]
  ]; updateMaTeX::usage = "suggested at the MaTeX GitHub repo."
EndPackage[]; DeclarePackage["MaTeX`", {"MaTeX", "ConfigureMaTeX", "ClearMaTeXCache","updateMaTeX"}];

However this leads to two issues:

  1. (Solved) The supposedly local variables json``download``target are touched in the MaTeX` context, and picked up by the auto-completion. It's a simple fix to add Remove[json, download, target] to the code, but I wonder why no $ModuleNumber was appended to the symbols.
  2. Autoloading does not work as expected. Type MaTeX in a new notebook and it is still undefined; evaluation causes this new symbol to be created in Global` . Typing MaTeX`MaTeX, it is undefined, but become defined as soon as it is evaluated; Global`MaTeX is simultaneously shadowed. At this point, the $\text{M}\!^\text{A}\!\text{T}\!_{\normalsize{\text{E}}}\!\text{X}$ document is accessible, but the symbol MaTeX(MaTeX`MaTeX) does not have any downvalues, and thus is not working.

Similar issues occur with the Rubi` package. Therefore I wonder:

  1. Is using BeginPackage["Package`"] outside the package .m a good practice?
  2. Why DeclarePackage does not work as expected?

Related Questions

  1. Automatically load packages at startup

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.