0

One of the features of BibTeX is that it discards all capitalizations in titles of the references. This unwanted feature can be coped with including a curly brace (i.e. {}) around the text that you want to have capitalization. This procedure should be done one by one. Fortunately, there is a macro that can be used to accomplish the task, this macro is

%SCRIPT
c = cursor
c.movePosition(1, cursorEnums.StartOfWord)
c.insertText('{')
c.movePosition(1, cursorEnums.NextCharacter, cursorEnums.KeepAnchor)
c.replaceSelectedText(c.selectedText().toUpperCase())
c.clearSelection()
c.insertText('}')

Such a macro or equivalent macros (that can be found on the interent) do the task one by one. I need some ideas how to implement that for an entire file, where searched for "title" in each BibTeX entry and put one pair extra braces around the title. Example:

Title  = {someTitle}

should become

Title  = {{someTitle}}

Points: 1. The number of spaces between the "Title" or "title" to "=" is not clear. 2. It is better not to alter those who already have double braces. 3. Just lines of the above format should be altered. 4. There might be and often is a comma (,) at the end of the line which should be preserved.

6
  • 2
    it is not a feature of bibtex, merely a style choice in the bibliography style you are using, so you could use a different bibtex style. – David Carlisle Oct 23 '17 at 19:19
  • 2
    Or to paraphrase @DavidCarlisle 's comment more succinctly: Don't do this! – Alan Munn Oct 23 '17 at 22:55
  • Can you explain how can I avoid missing capitalization? I use IEEE classes for article – Hamid Oct 24 '17 at 9:24
  • 1
    Can you give a few bib entry examples for us to try out on? For example, are the titles always in the form title = {...}? – Troy Oct 24 '17 at 11:19
  • 1
    The braces should go around only the first word of the title? Or every word? Or over the whole title phrase? Some examples of the desired output will also be appreciated. – Troy Oct 24 '17 at 15:21
3

Here's an attempt. Create a new macro/user script in TeXstudio and paste in the following:

%SCRIPT
function onFoundTitle(c){
var t = c.selectedText();
var dblOp = t.indexOf('{{'), dblCl = t.indexOf('}}');
if (dblOp<0 || dblCl<0){
    var op = t.indexOf('{');
    var cl = t.lastIndexOf('}')+2;
    t = t.substr(0, op) + '{' + t.substr(op);
    t = t.substr(0,cl) + '}' + t.substr(cl);
}
c.replaceSelectedText(t);
}

editor.search(/^\s*([tT]itle)\s*=\s*\{.*[(\},)\}]\s*$/,"g",onFoundTitle)

This script finds all instances of title={...} (and its various other combinations) using regex and calls the function onFoundTitle which adds in braces around the title.

Here are some of the bib entries that I used to test the script in various scenarios (see the bib entry keys for clues on what I am testing for):

@article{capitalT,
    author = {C.Schillings and A.M.Stuart},
    Title = {{Analysis of the ensemble Kalman filter for inverse problems}},
}

@article{dblbrackets,
    author={Alvin Blue},
    title   = {{some {tests} within brackets{again}}},
    journal = {Physical Review}
}

@article{nospaceNcomma,
    author={Girvan, Michelle and Newman, Mark EJ},
    title={{Community structure in social and biological networks}}
}

@article{alreadyBrackets,
    title   ={{Community structure in social networks}},
    author ={Girvan, Michelle}
}

NB. If I misinterpreted the requirements of the question, please give me more concrete examples to work with (like the ones I have above).

mwe bibtex

4
  • How do you know the methods of objects, for example how do you know that there is a selectedText method for "c". – Hamid Oct 26 '17 at 12:40
  • 1
    c is my variable name for the cursor object. when calling the function onFoundTitle from the editor.search(), the cursor object is passed as the first input argument by default. (see the texstudio manual for more details) – Troy Oct 26 '17 at 12:43
  • I get the what you say. However, I'm not sure we are using the same tool for development. Let me put it in this way. Is there any way to code a macro and preferably debug it in an IDE? Jetbrain would be perfect – Hamid Oct 26 '17 at 13:07
  • 1
    TeXstudio uses QTscript language for its macros, so if you want to test out/debug, the IDE would have to support that at the very least. Whether it can actually be done, I'm not so sure. You can try asking on the TS sourceforge discussion page -- Tim or Jan can probably give you a more definitive answer. I do my debugging from within TeXstudio itself. – Troy Oct 26 '17 at 13:13

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.