# How to distribute styles with packages?

I want to define some named styles with StyleData and StyleDefinitions that are either entirely new or inherit from default stylesheets and use these named styles across my package. These include styles for displaying objects introduced by the package, styles for package documentation, etc. Needless to say, I want these styles to work seamlessly in other environments when I distribute the package.

1. Where should I put style definitions within my package? How should I organize styles?
2. What is the scope of these styles? Are they only available when the package is loadad?
3. What are some guidelines to define distributed styles as general as possible, considering for example that users might use different stylesheets or environments.

For example I cannot specify a text color explicitly in my style, like FontColor -> Black, as it won't be visible in case a user relies on the ReverseColor stylesheet. Leaving the color undefined causes most styles to switch color in case background (and stylesheet) is switched. How can I define styles with colors that are aware of the background/stylesheet, without programmatically modifying global stylesheets at the user's machine?

• Put it in a Stylesheets folder and add {"FrontEnd"} to the "Extensions" in the PacletInfo.m. Read up on PacletInfo.m as it'll explain everything. Keep in mind that this only allows you to change your stylesheets, but just have your user use your stylesheets that come with the package. I do this to handle really complex front-end stuff like this IDE plugin (keep in mind that specific post is old and the IDE has had some major performance and appearance updates since). – b3m2a1 Sep 13 '19 at 9:07
• @b3m2a1 So this only works if the user manually sets the stylesheet, distributed with my package? Is there really no simpler method? – István Zachar Sep 13 '19 at 12:25
• do you want to hijack their system? What’s your goal here? In general, yes, to use package specific styles they need to select your style sheet from the stylesheet menu. If you set the package up correctly your stylesheet will be accessible from there. – b3m2a1 Sep 13 '19 at 16:02
• Usually that's coupled with some amount of auto-generated notebooks with the stylesheet you care about. Like you say you have package documentation, so your package documentation should just use your stylesheet. Or your various different color schemes can be toggled by some kind of UI element that swaps out the stylesheet. At the end of the day, styles in Mathematica are always bound to a stylesheet and unless you're going to hack the user's system you can't override the stylesheets that are already there. So you need to make your own stylesheets. – b3m2a1 Sep 13 '19 at 16:53
• No way to do that. Styles are part of the Mathematica front-end. Packages are part of the kernel. The paclet system has some extension mechanisms to bridge the gap, but they're still separate objects. And in any case, there's no concept of a global "style". Styles are attached to stylesheets. That's all there is to it. There's some amount of object-specific styling you can apply, but that requires hardcoding all settings into your object. Anyhow, if you're going to ask your user to load your package you can ask them to use your stylesheet. It'll be right there in the menu for them to choose. – b3m2a1 Sep 13 '19 at 19:01