Custom Command Highlighting in TeXstudio

I have defined several macros in my LaTeX report. For instance, following is a macro I defined for writing bold letter H. I have several macros like this I use throughout my work.

\newcommand{\channel}{\ensuremath{\mathbf{H}}}


Whenever I use \channel, TeXstudio highlights it as red saying unknown-command. But it is indeed supported by the auto-completion feature. I want to stop TeXstudio from highlighting it as red (as it is annoying and affects readability). Is there any way to do this?

Update---

After seeing the comments, I realize I forgot to include a important thing. I always write these macros and package calls all inside a single file. Then I input this file in the LaTeX file I am writing. But now I guess I am asking a bit too much. I mean I require the software to recognize the macros which I have input from another file. Nevertheless I was wondering if there was any solution.

• Welcome to TeX.sx! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). You can also use backticks  to mark your inline code. – Corentin Dec 14 '12 at 10:49
• \documentclass{article}\newcommand{\channel}{\ensuremath{\mathbf{H}}}\begin{document}\channel\end{document} works as expected in TeXStudio 2.5.1 with TL2012. No red highlighting. – hpesoj626 Dec 14 '12 at 14:13
• @hpesoj626 please see the update – dineshdileep Dec 15 '12 at 2:05

Normally, TeXstudio recognizes a \usepackage{…} in the main file and does load the auto-completion list (.cwl), but TeXstudio isn’t intelligent enough to recognize packages loaded in external files.

You could manually select the auto-completion lists for packages loaded in the external file, but then they are active in every document.

For custom commands I only see a solution with a custom .cwl file which, of course, has the same disadvantage (always active if not disabled).

• That is ok, I almost universally use them. where do I place that file? – dineshdileep Dec 15 '12 at 2:58
• @dineshdileep See my linked answer for new Windows’s (%APPDATA%\texstudio\ ); the TeXstudio user manual also states: “This directory is placed in ~/.config/texstudio under linux and usually c:\Documents and Settings/User/AppData/Roaming/texstudio under windows.” – Qrrbrbirlbel Dec 15 '12 at 3:02

I had the same problem, I found a way to solve it (I have TeXstudio installed on Ubuntu 16.04). In the "structure" panel (on the left of the editor), simply click on the name of the file you want to input.

Here is a MWE, with some snapshots to make it clear : I created a file def.tex just containing the line \newcommand{\channel}{\ensuremath{\mathbf{H}}} and a file testDoc.texcontaining the following lines: \documentclass{article}\input{def}\begin{document}\channel\end{document} As expected, \channel is highlighted in red as shown on this snapshot:

Now, if I click on the file def in the left panel called "structure" (this will simply open def.tex in the editor), and go back to testDoc.tex` the red highlight disappears. Moreover, autocompletion now includes the suggestion for channel:

• Welcome to TeX.SX! How do you solved the problem? Could you explain a little bit? – Bobyandbob Mar 6 '18 at 12:38
• Hi ! I edited the answer so that it's a bit more clear and easy to find the important info. Basically, you just have to open the file you want to input in the editor and then go back to the main file. – Martin Mar 6 '18 at 16:05