0

I am encountering an issue with the LaTeX Workshop extension for Visual Studio Code. I'm attempting to format my .bib files using the latex-workshop.bibalign command, as per the guidelines provided in the LaTeX Workshop wiki.

However, when I run the command, I receive the following error message:

Command 'LaTeX Workshop: Align BibTeX file' resulted in an error
Expected ... but '@' found.

enter image description here

The error suggests a syntax issue with the BibTeX file, but I am unsure what's causing it or how to fix it. The file contains regular BibTeX entries; I haven't made any unconventional modifications.

Has anyone encountered this error before, or does anyone know what might be causing it? Any insights or suggestions on how to resolve this would be greatly appreciated.

Additional Info: I'm using MiKTeX on Windows 10, and my .bib files are a mixture of BibTeX and BibLaTeX.

P.S. I have also posted this question here on LaTeX WorkShop GitHub repository discussions and here on r/LaTeX subreddit.

2
  • 1
    well I don't have vscode and can't test your script but I took a quick look at your bib, and would recommend not to use % inside of entries. If you want to comment a field you should rename it, so use something like Xurl= instead of %url= . And if you want to comment a full entry you can simply remove the @ from the type. Commented Jan 25 at 15:01
  • @UlrikeFischer amazing. I searched for the %\s* regular expression (RegEx) and replaced them with X. Now, it works like a charm! But the question arises then: how am I supposed to comment something out in my .bib files? Is it a bug that we should report?
    – Foad
    Commented Jan 25 at 15:16

1 Answer 1

2

In your real bib-file (in one of the links) shows that you used comment chars inside bib-entries:

@Article{sakama2022,
    AUTHOR = {Sakama, Sayako and Tanaka, Yutaka and Kamimura, Akiya},
    TITLE = {Characteristics of Hydraulic and Electric Servo Motors},
    JOURNAL = {Actuators},
    VOLUME = {11},
    YEAR = {2022},
    NUMBER = {1},
    ARTICLE-NUMBER = {11},
%    URL = {https://www.mdpi.com/2076-0825/11/1/11},
    ISSN = {2076-0825},
    DOI = {10.3390/act11010011}
}

This is not correct bib-syntax. The LaTeX companion (third edition) (shameless advertising) says about comments in the .bib-file:

Note that LaTeX's comment character % is not a comment character inside .bib database files and even leads to parsing errors [...]. Thus, to comment a field in an entry, change the name of the field [...]. To exclude a full entry, remove the starting @-sign.

So to exclude the url do something like this:

@Article{sakama2022,
    AUTHOR = {Sakama, Sayako and Tanaka, Yutaka and Kamimura, Akiya},
    TITLE = {Characteristics of Hydraulic and Electric Servo Motors},
    JOURNAL = {Actuators},
    VOLUME = {11},
    YEAR = {2022},
    NUMBER = {1},
    ARTICLE-NUMBER = {11},
    XXXURL = {https://www.mdpi.com/2076-0825/11/1/11},
    ISSN = {2076-0825},
    DOI = {10.3390/act11010011}
}

To exclude the entry remove the @ before the entry.

Article{sakama2022,
    AUTHOR = {Sakama, Sayako and Tanaka, Yutaka and Kamimura, Akiya},
 ....
}

(The entry should then not contain @-signs, as that would start a new entry and confuse the parser.)

You can additionally add % in this case (then biber will not report this as junk):

%Article{sakama2022,
%    AUTHOR = {Sakama, Sayako and Tanaka, Yutaka and Kamimura, Akiya},
% ....
%}

You must log in to answer this question.

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