User provided variable names via '$VAR'/1

The documentation of the write_term/[2,3] options tells
me that there is numbervars/1 option, with the following behaviour:

If N is an atom it is written without quotes. This extension
allows for writing variables with user-provided names.
https://www.swi-prolog.org/pldoc/doc_for?object=write_term/2

Does this option only work for some atoms and not for all atoms?
Is there an option to enable it for all atoms, or should I use some

portray hook. How can this be done, that all atoms are accepted?
Currently I get this result, the atom ‘Fido$’ is not accepted:

?- X = '$VAR'('Fido'), write(X), nl.
Fido
X = Fido.

?- X = '$VAR'('Fido$'), write(X), nl.
$VAR(Fido$)
X = '$VAR'('Fido$').

The atom must syntactically be a variable name. This prevents injection attacks if the variable names are somehow provided by the end user of a service.

You can of course define a portray/1 clause to do as you want. Not sure whether or not you can use ‘$VAR’ in that case, i.e., I don’t know the order in which these are processed. I’d use something else to be safe and portable.