6

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?

3struck
  • 63
  • 1
    do you add your path to miktex settings and than renew database? see instruction for "console": https://miktex.org/howto/miktex-console. welcome to tex.se! – Zarko Oct 06 '18 at 03: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 06 '18 at 07: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 06 '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 06 '18 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 06 '18 at 19:31
  • 1
    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. –  Oct 06 '18 at 20:25
  • @KJO I do not have a MiKTeX console on my computer as per the visual in the link provided by Zarko. I do have a MiKTeX Settings application that has the necessary tools to register the file path and renew FNDB (both of which I have done). The file path is still listed under Roots on the settings console when I restart the console. The console gives me no indication or option for running as user or administrator. – 3struck Oct 06 '18 at 21:31
  • Sorry assumed you are using console as it so much easier, the system CLI commands are (assuming your "me" is only latin aTOz with no spaces, punctuation or accents) and of course miktex bin is on your system path. [1] initexmf --user-roots=C:/Users/me/texmf --update-fndb=C:/Users/me/texmf --update-fndb [2] type "c:\your path to MiKTeX app\texmfs\install\miktex\config\miktexstartup.ini" [3] check it shows correct [Paths] UserRoots=C:/Users/me/texmf –  Oct 06 '18 at 22:12
  • Show a screenshot how the file path is listed as root. Regarding your number of typos and missing info I want to see the path and not your recording. – Ulrike Fischer Oct 06 '18 at 22:27
  • Having to presume from your paths and comments your running on windows with just an installer I suggest even if your trying to keep to the minimum that the console package is only 200kB of pure gold in a situation such as this, if you have it installed without your knowledge then running c:> miktex-console should invoke it –  Oct 06 '18 at 23:06
  • @KJO Can you clarify what you mean by "MiKTeX app?" I would like to have the console for this and future projects, I'm just not sure exactly how to download it correctly. – 3struck Oct 06 '18 at 23:19
  • Ok my bad (loose) use of terminology.In MiKTeX the Console package is the GUI frontend which allows you to set paths. by "path to Miktex app" I mean something like "program files (x86)\miktex2.9" it will depend on how many bits your windows is and which locale your working in. –  Oct 06 '18 at 23:35
  • Thus on reading your question more carefully you do have the GUI but the path you set is wrong which is why @UlrikeFischer has asked for a screenshot of the settings > directories tab –  Oct 06 '18 at 23:42
  • Ok now I see your using older (depreciated) console any reason you have not updated to new console via Package Manager?. Though if it works don't fix it ?. Your path as shown seems correct. can you find and check contents of miktexstartup.ini ? –  Oct 07 '18 at 00:31
  • I did not know that the console that I am using is out of date. I will work on updating it soon. I followed your code for [2] (to find miktexstartup.ini) and Windows tells me The system cannot find the path specified. I searched and it appears that I do not have a texmfs folder in my MiKTeX 2.9 folder. Is there another folder I should be using? – 3struck Oct 07 '18 at 00:49

2 Answers2

3

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 07 '18 at 00: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 –  Oct 07 '18 at 03: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 –  Jan 14 '19 at 14:10
  • 1
    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
1

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!

Tommiie
  • 526