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?

  • 1
    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 at 3:54
  • 1
    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 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 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 at 19:27
  • @alephzero The .sty file works fine when I put it in the same folder as the main.tex file. I'm asking where should my .sty file go in this case? The other instructions aren't working (unless I'm following them wrong.) – 3struck Oct 6 at 19:31
up vote 1 down vote accepted

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...\…

enter image description here

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 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 – KJO Oct 7 at 3:21

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.