# Windows MikTeX can't find my .sty file

I posted a question like this earlier but I'm re-asking because I didn't ask properly before.

I created a .sty file (preamble.sty) to help clean up my preamble but I'm having trouble actually using the packages in my document.

Other questions I have followed (in order) without any luck:

-Create a local texmf tree in MiKTeX My file path to the .sty file is C:/Users/me/texmf/TeX/LaTeX/PreambleStuff. I used the MikTeX GUI to add it as a root in the "Settings," then made sure I clicked "Refresh FNDB"

-Where do I place my own .sty or .cls files, to make them available to all my .tex files? I used the kpsewhich -var-value=TEXMFHOME command line and the command prompt window did not show any file path, just displayed a new C:\Users\me> prompt. Does this mean that I don't have a texmf home directory? I also used the command kpsewhich preamble.sty which shows the correct file path to the file (see file path above).

-https://docs.miktex.org/manual/texfeatures.html#includedirectory I typedlatex --include-directory=C:/Users/me/texmf/TeX/LaTeX/PreambleStuff preamble.sty and the command window shows ! LaTeX Error: \usepackage before \documentclass. See the LaTeX manual or LaTeX Companion for explanation.

The last part raises questions of whether or not I actually wrote my .sty file correctly, but I am mostly concerned with getting MikTeX to find the file and include it properly in each document. What else can I do or what am I doing wrong?

• do you add your path to miktex settings and than renew database? see instruction for "console": miktex.org/howto/miktex-console. welcome to tex.se! – Zarko Oct 6 '18 at 3:54
• The path is wrong. The tex folder is missing. The sty should be in texmf\tex\latex\preamblestuff.the root is then the texmf. – Ulrike Fischer Oct 6 '18 at 7:25
• You shouldn't be trying to compile your .sty file on its own. Your main .tex file should say something like \documentclass{…} \usepackage(preamble) \begin{document} ... \end{document}. To get that working, you can put preamble.sty in the same directory as your main .tex file. When that compiles successfully, then go back to figure out where you really want to put the .sty file so you can use it in other documents as well. – alephzero Oct 6 '18 at 14:00
• @UlrikeFischer That is a typo. I have updated the post to correct that. Thank you for pointing it out. – 3struck Oct 6 '18 at 19:27
• Please confirm in your question/answer that avoiding using consol administrator you "Registered" C:/Users/me/texmf per link given by @zarko and then renewed FNDB (via tools) wait till it completes then exit MiKTeX console and re-enter as basic (not admin) user to verify it stuck. – user170109 Oct 6 '18 at 20:25

Your local TEXMF tree should not be a subfolder of MiKTeX\texmfs , although it can be a sibling tree as in the screenshot. The key is it ends texmf not texmf\tex\lat...\…

Ideally it should be in an area where you have no user control issues and a common suggestion is C:\users\yourname\mytexmf as similar to ~/mytexmf of Linux. However due to the variety of user names it is better to use something like c:\miktexdata\mytexmf avoiding spaces, punctuation or accented characters.

Once you are sure it looks ok, go to Tasks and Refresh file name database. Exit the console and check MiKTeX is not running in the background. Re-enter MiKTeX console and check the setting is still the same.

IF you are not running console you can do the same from the command line using

initexmf --user-roots=c:\mytexmf --update-fndb=c:\mytexmf --update-fndb


or as suggested in another thread by Ulrike Fischer

initexmf --register-root=c:\mytexmf


If your still having problems, on a portable install that setting may be stored in a single miktexstartup.ini file, check its contents and there is not a second file with that name. In a basic user install it is stored in the registry under Computer\HKCU\Software\MiKTeX.org\MiKTeX\2.9\Core. If your confident with searching you could check the entry is identical.

To test it works download a well tested additional package such as mwe.tds.zip and install that (unzip the contents so included folders doc source and tex are included in your personal texmf as mytexmf/tex/ mytexmf/doc mytexmf/source)

Ensure you Update file name database either in console or via command line

Prepare a simple MWE file

\documentclass{article}
\usepackage{mwe}
\begin{document}
\blindtext
\begin{figure}
\includegraphics[width=.48\linewidth ]{example-image-a}
\includegraphics[width=.48\linewidth ]{example-image-b}
\caption{MWE to demonstrate how to place to images side-by-side }
\end{figure}
\blindtext
\end{document}


it should run and you will see a reference to C:/mytexmf\tex\latex\mwe\mwe.sty thus proving the personal texmf is set correctly for a .sty NOTE: MiKTeX uses / for the stored absolute part to texmf and \ for the relative parts below that, this is acceptable to windows.

• My first post was not as clear as I thought. My local TEXMF tree is at C:/Users/Me/texmf as prescribed in the first link of the original post. My MiKTeX settings application shows this as the file path. – 3struck Oct 7 '18 at 0:24
• I have been looking to find a useful MWE test case, which I have included in my answer. It will prove if MiKTeX recognises your TEXMF/TDS as valid. Any other package that fails after that is probably not TDS compliant – user170109 Oct 7 '18 at 3:21
• What settings should be added or modified in the miktexstartup.ini file? Although I added the directory in the MikTeX console and updated the FNDB, I still can't access my custom sty files. – Tommiie Jan 14 '19 at 13:00
• @Tommiie My answer was directed to the main question so would need to know what point you are starting from. If your case is different from the above and the answer does not work it may be best to raise a fresh question with details of this and other answers you tested, it may be flagged down as duplicate if you don't explain the steps you have attempted without success, clearly show OS, & MiKTeX versions and how installed (portable/install paths) also explain what folder locations you have tested that do or don't work since your likely be told by default to put the .sty alongside the .tex – user170109 Jan 14 '19 at 14:10
• Never mind. It seems I've hit a bug, added my own answer just as info for someone else who might hit the same issue. – Tommiie Jan 14 '19 at 14:12

For me I hit a bug in MikTeX. To solve the issue I used the answer provided by @KJO and in addition, I manually edited the file miktexstartup.ini in the directory <installdir>\texmfs\install\miktex\config:

;;; MiKTeX startup information

[Auto]
Config=Portable

[Paths]
UserRoots=D:\miktex-portable\mytexmf


For me the <installdir> was D:\miktex-portable. After manually adding the line UserRoots, restarting MikTeX portable, and building the FNDB, it worked!