I defined a new command as:


so to make a new equation I do:

 \eq{equation stuff here}{label here} 

But since I've not used the equation environment explicitly, texstudio highlights every math symbol in the equation. It is really annoying. Is there a way around this?

  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. (I moved my first comment to an answer, since I'm very confident that there is no answer. If someone proves me wrong, I'll be impressed :-). ) – Sean Allred Jul 11 '13 at 19:37
  • 3
    I advise you not doing that, because you lose information. For instance, you can't look for all the labels with a simple find function for \label. Maintenance of compact code is harder. – egreg Jul 11 '13 at 19:38
  • 1
    I suggest you to use the capability of TeXstudio to autocomplete the commands instead of defining new ones. – Sigur Jul 11 '13 at 19:44
  • egreg, I do prefixes to my labels, e.g. fig: or eq:, so finding them wont be a problem. Vedran, That seems like a reasonable compromise, thanks a lot. P.S. Being a new user, I cannot add comments, so I must post this as an answer. – user33542 Jul 11 '13 at 19:57

Given the nature of TeX's language, I don't think there is a good, reusable solution to this one. Syntax highlighting is something done usually using regular expressions, but TeX is (literally) a class of languages higher than regular expressions can cover. Getting the syntax highlighting right would require some serious umph behind TeXStudio's parser - paramount to including a TeX distribution in-house.

See also Is there a BNF grammar of the TeX language?.

  • I was a bit pessimistic about the problem. I guess I can just turn off the highlighting in texstudio. Thanks for the reply. – user33541 Jul 11 '13 at 19:34

If you're content with replacing the command \eq with the environment eq, this should be doable. Just define your own CWL file with the line


Then include this file in options, under Completition.

More on the CWL format can be found here and the basic info on the file itself is here.

  • Since I don't use TeXStudio anymore, I didn't know about this functionality. Neat! I would note to @Harsh though that environments can also take arguments. So, whether or not it's A Good Idea, you could incorporate the automatic label as an argument in much the same way as you would do in \newcommand. – Sean Allred Jul 11 '13 at 20:32

You can define something like that:



and you have both shorthand and highlighting!

(Read Knuth's TeXbook rather than LaTeX tutorials to know how to define commands properly. ;-) )

Here are some more of my own definitions:




\Align at$${2}
  • using $$ in latex removes the ability to use some useful features that have been provided by the named latex environments, such as \qedhere with amsthm. although ingenious, this is not a practical solution. – barbara beeton May 13 '15 at 16:21
  • These are the best set of macros I have found so far. You get the highlighting and also the nice detail that TeXStudio can give you a formula preview when you hover over them with the mouse, which doesn't happen in \begin{equation}. Really cool! – Santi Mar 11 '17 at 10:06

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.