I am having a somewhat complex issue with the knowledge package. A MWE is the following:




\hypersetup{ % Set up hyperref options


\knowledgedirective*{automatic in command}{autoref,style=no,intro style=no}


% Colors in math mode, with correct spacing
% https://tex.stackexchange.com/questions/21598/how-to-color-math-symbols





  \section{A section}

  \Cref{sec:sec} is a section


First, I’d still like to have internal links – such as the section reference – colored. So AFAIK I have to set colorlinks=true.

Now the issue is that the knowledge package does a lot of linking. The main use I’d like to have for this is to have all notations (such as foo here) refer to their definition, so that people can go look them up if they are unsure of their meaning. So far, so good.

I definitely do not want to have all those colored, because that would turn most of my mathematics into the link color – not very informative. Now knowledge provides the knowledgestyle command to give a specific color to each knowledge command. So I could just put black in there, so that foo is printed in black.

Now the issue is that later on I want to have different parts of equations colored – I’m doing programming languages theory, that’s basically syntax highlighting. So I define the targetcolor macro, and use it. But then this clashes with the two former: If I set the knowledgestyle to black, I lose because foo is black instead of green. If I do not set knowledgestyle, then the link color wins again and foo turns red.

A solution would be to deactivate link colors in math environments. But I do not know how to do that. I searched around and found AtBeginEnvironment, but I am not an expert enough to understand how to use it with mathematical environments (are these actually evene environments?).

  • I’d like to add the knowledge tag, but apparently I do not have enough reputation. Maybe someone with the right authorizations can do that for me? Apr 20, 2022 at 15:10
  • 1
    you could try \everydisplay{\hypersetup{allcolors=.}}. Side remark: the next xcolor version will define a \mathcolor command. Apr 20, 2022 at 15:17
  • This seems to do the trick! Given the name of the command, I guess it only works in displayed math? Is there an equivalent for inline mathematics? Apr 20, 2022 at 15:23
  • Nevermind, some searching did the trick now that I know about \everydisplay :) It’s everymath. Do you want to give this as an answer, so that I can accept it properly? Otherwise I’ll self-answer, but I want to give you credit. Apr 20, 2022 at 15:25

2 Answers 2


You can try \everydisplay{\hypersetup{allcolors=.}} and \everymath{\hypersetup{allcolors=.}}. Then hyperref will pick up the current color for the links. (Completly disabling the coloring doesn't work, this needs the new hyperref driver from pdfmanagement-testphase).

Be aware that other packages or code can overwrite this.


Another solution, maybe more precise in its scope, is to use a modified version of the \cmdkl macro which deactivates link colors:



Note that the wrap= directive of knowledge does not work since it is applied innermost, which means here inside the linking command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .