# TeXstudio: Can I put multiple packages in a separate file and still have the autocompleter recognize their commands?

This is a follow-up question to

# The Problem

Over the years, I have collected quite the number of useful packages and commands. Until now, I had them saved with TeXstudio as a template so that I could start a new file from it. This is similar to copy-pasting everything whenever you make a new file which raises some maintainability and duplication issues.

# What I tried

I tried to separate the preamble into a test.sty file, placed it in a new root (../tex/latex/test.sty), added the root in MiKTeX Settings (Admin) and pressed "Refresh FNDB" to include it.

When I compile with TeXstudio, it locates test.sty and everything is fine and dandy. However, the autocompleter neither recognizes the packages nor their commands.

From what I gathered here, if MiKTeX is set up, TeXstudio compares test.sty, a custom, local package, with the list of packages on the cloud from MiKTeX using mpm.exe --list. This may be the issue as running that command and saving its output in a temporary .txt file, my test.sty does not appear!

Am I attempting to do something currently impossible, or am I just being stupid?

Here is a MWE of my attempt, and a picture of the autocompleter.

## myTex.tex

\documentclass{article}
\usepackage{test}
%\usepackage{mathtools}

\begin{document}

% the flalign* env. from mathtools in test.sty is not recognized before compiling.
\begin{flalign*}
2x+3 &= 5 \\[1mm]
x &= \dfrac{5-3}{2}
\end{flalign*}

\end{document}


## test.sty

\ProvidesPackage{test}[2017/10/14 The Amazing Squirrel's collection of packages]

\RequirePackage[utf8]{inputenc}
\RequirePackage{mathtools}
\RequirePackage{amssymb}
\RequirePackage{logicproof} %Fitch-Style Predicate Logic Proof in the style of Huth & Ryan

\endinput


# Technical info.

I have TeXstudio 2.12.6 and MiKTeX 2.9 running on a Win. 7 Pro. Lenovo laptop.

• I'm taking a wild guess here, but can you try setting up a custom cwl (as per my answer in the linked question), with the contents being #include:mathtools, #include:amssymb etc.? – Troy Oct 14 '17 at 15:07
• Nice one, Troy! Adding a test.cwl file (path: %appdata%\texstudio\completion\user) with what you suggested did the trick after I restarted TeXstudio! Although I have to add every package manually to the .cwl file, I still find it amazing that they can handle packages as well as commands. – Aram Oct 14 '17 at 15:25

In order to get TeXstudio to recognize commands from included packages (in particular for your case, included via .sty files), you need to set up a custom .cwl file since these files control the autocompletion feature of TeXstudio. Refer to my previous answer for details on creating your custom .cwl files.

Here, instead of adding commands one by one into your custom .cwl file, since you are including packages already have their own .cwl files, e.g. mathtools, amssymb packages, you can use #include:<packagename> to load packagename.cwl.

For example, in test.cwl:

#include:mathtools
#include:amssymb


and repeat this for any other packages that you are adding in your .sty file.

Just remember to activate it via Configure TeXstudio -> Completion if it is not automatically picked up by TeXstudio.