4

TeXstudio's autocomplete suggested \microfarad as a command so I attempted to use it but received an "undefined control sequence" error. There are easy workarounds (\micro\farad and \micro\F), but why does autocomplete think \microfarad exists if it apparently doesn't? I had never used \microfarad before because I didn't know it "existed" until I started typing in \micro\F and noticed the suggestion.

This appears to be the case for other commands like \microampere, \microgram, etc. I noticed the problem with \microfarad because there are shorter commands for the other units (\uA, \ug, etc.) but \uF doesn't exist either.

Why does TeXstudio's autocomplete suggest these non-existent commands?

I've found this problem on two separate Windows 7 machines, and strangely I cannot find an siunitx.cwl file on either machine.

MWE:

\documentclass{article}
\usepackage{siunitx}

\begin{document}
    \SI{1}{\microfarad}\\ % undefined control sequence
    \SI{1}{\micro\farad}\\ % works
    \SI{1}{\micro\F} % works
\end{document}
Null
  • 1,525
  • 2
    Autocomplete has not the slightest idea which commands are defined and which not. Don't let the editor trick you ;-) – Johannes_B May 07 '15 at 18:13
  • By the way, good example. – Johannes_B May 07 '15 at 18:13
  • @Johannes_B You're right; I re-worded the question a bit to ask why autocomplete is wrong. – Null May 07 '15 at 18:17
  • @Johannes_B some editors (and TeXStudio should be among them) have basic parsing capabilities (of course don't work with very complicated definitions), so your statement is not completely true. – giordano May 07 '15 at 19:05
  • @giordano I know, somebody told me that TeXstudio is even capable of learning new commands. I am not sure where the list is saved and editable and i also don't know after how many instances an item is added to the list. – Johannes_B May 07 '15 at 19:07
  • Anyway, a very old version of siunitx had a macro called \microfarad, perhaps TeXstudio completion table isn't up-to-date. – giordano May 07 '15 at 19:47
  • So 1. you checked the siunitx package in the auto-completion tab in the options editor and 2. yes, if you put \newcommand{\microfarad}{\micro\farad} in the preamble and save the document once, Texstudio should be able to auto-complete \microf (or even with less characters) after that. – henry May 08 '15 at 20:44
  • @henry Yes, the siunitx package is checked in the options editor. I know I can create a new command, I'm curious why TeXstudio's autocomplete is picking up a non-existence command. And are there any other commands with a similar problem? – Null May 08 '15 at 21:19
  • Which operating system do you use? If it's a Unix-like (GNU/Linux or Mac OS X) try to run locate siunitx.cwl to identify the autocompletion file for siunitx. – giordano May 09 '15 at 09:42
  • @giordano I just updated the question. I can't file the .cwl file for siunitx. I've checked on two different machines. – Null May 11 '15 at 13:38

1 Answers1

3

I think that this is a bug of TeXstudio. The problem is that TeXstudio has auto-completion support for certain commands hard-coded in, most likely for performance reasons. This can be easily checked by looking at the texstudio.exe in a text editor and searching for \microampere (line 68436 in version 2.9.4).

So I would say this is TeXstudio's bug and you should submit it in their bugzilla. I think this is a case for many other commands, so you could also suggest general cleanup of the hard-coded lists of commands.

Edit: I checked the source of TeXstudio 2.9.4 and really, the file completion/siunitx.cwl contains \microfarad, etc. These files must then be compiled into the binary which is distributed.

Augustin
  • 5,695
  • 1
    You have the source, one doesn't need to open a binary file to find it out. \microampere is in completion/siunitx.cwl. What's strange is that that file is different from the one present in the repository. It seems they have a repository but use something else as base to build the executable. – giordano May 11 '15 at 14:10
  • @giordano: I just checked the source code and edited my post as you added the comment. This is strange indeed. – Augustin May 11 '15 at 14:15
  • I'm using TeXstudio 2.9.4 on Linux and I don't have any siunitx.cwl even I can check it in the Options/Configure menu. – Sigur May 11 '15 at 14:17
  • @sigur: We are talking about the source code, though. See giordano's comment above containing the link. – Augustin May 11 '15 at 14:20
  • @Augustin, yes, I know. I just said that I can not find any cwl file on my system containing \microfarad on it. So how TXS could suggest it to me? – Sigur May 11 '15 at 14:24
  • It is hard-coded in the TeXstudio binary. Try searching for "microfarad" inside texstudio.bin on your system. – Augustin May 11 '15 at 14:31