I'm new to LaTeX, so this might be a stupid question, but is there a way how I can define colors in one file and then use them by their name in another document? I'm thinking of something like this:

% myColorFile
\definecolor{mycolor}{rgb}{29, 66, 129}

and in the main file:

    % mycolor from myColorFile
    \textcolor{mycolor}{Some colored text}


\definecolor{mycolor}{RGB}{29, 66, 129}% RGB not rgb, rgb is 0-1 range
\definecolor{myzzz}{rgb}{0, .5, .7}

in mycolors.sty

then use


in any document where you want these colours.

  • Where do I save mycolors.sty to on Windows? I'm using the MikTex distribution – s6hebern Jul 31 '19 at 9:28
  • simplest is to put it in the folder with your document then it will work, to save copying it when you want a new document you will be able to put it in the default search path, in texlive that would be %HOME%/texmf/tex/latex, miktex will have a similar default but I'm not sure which, some miktex user will comment here probably. But you can test the file with it in the document folder first. – David Carlisle Jul 31 '19 at 9:30
  • Worked perfectly, thanks! I needed to follow these steps: miktex.org/faq/local-additions and then register this path through the MikTex Console: %USERPROFILE%\Roaming\MiKTeX\mytexmf. Just putting the *.sty file in the same directory as the actual main document worked as well. – s6hebern Jul 31 '19 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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