2

I've made a mymacros.sty file which I would like my LaTeX files to be able to access with commands that I've defined. I've managed to get it to work by putting \usepackage{mymacros} in my preamble.

However when I try to autocomplete I can't. I looked at this question:

The first it recommends is to have mymacros.sty open in the editor. But this doesn't work.

The second is to activate the option Editor -> Automatically load included files in the configure TeXstudio options panel. However while I have an Editor tab , there is no such option there.

The third is to using .cwl files, however I'm not sure how to go about this. In the completion tab I've noticed that there is a mymacros.sty option that has come up, which I ticked but that has had no effect. Do I need to make my own mymacros.cwl file? I've tried to look this up but haven't had any luck.

Anyone have any ideas? Thanks in advance!

  • Which TeXstudio version are you on? Under the Configure TeXstudio options, on the bottom left, there is an option to toggle advanced options. Make sure that is ticked, then check the Editor tab again. – Troy Mar 30 '17 at 15:20
  • Ah thanks! So I've figured out how to check that box now, but annoyingly its still not working any ideas? My version is 2.12.2. – Sam Davenport Mar 30 '17 at 15:34
3

I'm afraid I can't exactly diagnose your problem , but you can create your own .cwl file. Hopefully this is an acceptable alternative.

Reference: http://texstudio.sourceforge.net/manual/current/usermanual_en.html#CWLDESCRIPTION

1) The first step is to find the directory where the .cwl files are stored. If you're on Windows, the custom .cwl files are stored in .\AppData\Roaming\TeXstudio\completion\user directory. If in doubt, go to Help->Check LaTeX installation from within TeXstudio and search for Setting file. The directory should be printed out for you.

Check latex installation

2) Go to Notepad or any other text editor (TeXstudio works too!). The command syntax for the .cwl file is as follows:

<command>[#classification]

For a list of classification styles and what they do, refer to the link above, section 4.13.3. For now, try adding just one line to the text file:

\ThisIsMyCommand#n

and save it with a file name of your choice. As far as I know, this doesn't have to coincide with your .sty name, so let's choose randomcwl.cwl as a file name. Ensure that it is .cwl file.

notepad

3) Go ahead and place this file into your .cwl directory from Step 1.

4) Now, if you go to Configure TeXstudio -> Completion, You'll find the random.cwl choice has popped up. Check the box.

random

5) And test it out!

it works!

  • I already tried this and still can't get TeXstudio to autocomplete my macros when using a mymacros.sty file... maybe is a bug in 2.12.8? – Saavestro Apr 16 '18 at 19:31
  • 1
    @Saavestro No, I tried on 2.12.8 and it works. More details are probably needed -- if it's going to be exclusively a TXS issue, I would suggest opening an issue on the project Github page instead of on Stackexchange (more appropriate, and more likely to receive proper help) – Troy Apr 16 '18 at 22:01
0

I had the same issue. Since the macros defined in style file didn't appear in auto completion, I copied them in the main file (just temporarily) and it works fine. It's a simple workaround though not the best solution.

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.