2

Minimal example:

BeginPackage["plots`"]
s::usage = "s[max] plots ..."
x
y
Begin["`Private`"]
s[max_] := 
 Plot[Sin[x], {x, 0, max}, AxesLabel -> {HoldForm@x, HoldForm@y}]
End[]
EndPackage[]

After executing s[...] labels are x and y. But if I have (before or after package loading) some definitions for x and y I will get warnings abot multiple contexts and shadowing.

I can remove x and y from exporting part of package, but then I get plots`Private`x and similar for axes labels.

I used to set labels with HoldForm@x to avoid possible definitions for x and to have usual TraditionalForm for label.

How to solve this? Thanks.

xzczd
  • 65,995
  • 9
  • 163
  • 468
LittleCat1
  • 105
  • 1
  • 6
  • 1
    Why not using string? – xzczd Jul 04 '23 at 02:53
  • @xzczd, please elaborate. How to combine string and TraditionalForm? – LittleCat1 Jul 04 '23 at 02:55
  • You mean you need it be italic? Then Style["x", Italic]. You can also select the symbol in string and press Ctrl+i. – xzczd Jul 04 '23 at 02:59
  • @xzczd, plrobably this is a way to go. But I mean, in a notebook I use Axeslabel ->{HoldForm@x,HoldForm@y} and get nicely formatted labels. Can this be done with packages and all this "nightmare" of contexts? – LittleCat1 Jul 04 '23 at 03:02
  • @xzczd, I tried your suggestion with Style["\!\(\*SubscriptBox[\(\[Beta]\), \(y\)]\)", Italic] and HoldForm[Subscript[\[Beta], y]], they look different, \[Beta] e.g. – LittleCat1 Jul 04 '23 at 03:07
  • If you insist on the HoldForm approach, one possible workaround is Internal`$ContextMarks = False 2. For the \[Beta] case you don't need the Italic style.
  • – xzczd Jul 04 '23 at 03:13
  • @xzczd, OK, your first suggestion Internal`$ContextMarks = False works great! Thank you! – LittleCat1 Jul 04 '23 at 03:28