Hi,
I know that you can use TextMate to cite from a BibTeX file but as of now this only works for one BibTeX file. I have several BibTeX files which I maintain seperately and since this works much better for me I thought I'd give BibDesk a try with which you can have several BibTeX files open at the same time and cite from them with BibDesk's system wide citing service. I get this to work in TextEdit and TeXShop but not TextMate :-(
To use the service you type \cite{H}, leave the cursor at H and type Alt-Escape; this will give you a list of all references that contain H, but in TextMate this only cylcles through several words containing H. In TextMate the Escape key is set to "Next Completion", so I guess that this either clashes with BibDesk's hot key or TextMate doesn't support BibDesk at all.
If anybody has any hint how to overcome this either with TextMate supporting several BibTeX files or how to get BibDesk to work with TextMate I'd be very grateful!
Best wishes, Thomas
Ciao, Thomas
-- Thomas Schröder +++ hydrochlorix@gmx.net
On Apr 12, 2005, at 13:22, Thomas Schröder wrote:
To use the service you type \cite{H}, leave the cursor at H and type Alt-Escape; this will give you a list of all references that contain H, but in TextMate this only cylcles through several words containing H. In TextMate the Escape key is set to "Next Completion", so I guess that this either clashes with BibDesk's hot key or TextMate doesn't support BibDesk at all.
I'm not exactly sure how BibDesk works -- it does install an input manager, but maybe this is to patch the NSTextView of the application, in which case it won't work with TM.
However, BibDesk does support AppleScript to lookup a search string for completion, so what you can do is go to menu Automation / Run Command / Edit Commands...
Make a new command with input: none, output: insert as snippet, key equivalent: option-escape and the actual command:
res=`osascript <<EOF tell application "Bibdesk" to set candidates to search for "$TM_CURRENT_WORD" with for completion tell application "System Events" activate choose from list candidates end tell EOF` osascript -e 'tell app "TextMate" to activate' &>/dev/null & echo -n ${res:${#TM_CURRENT_WORD}}
If you type something, press option-escape, it will lookup the word to the left of the caret, showing matches (from BibDesk) using an AS dialog, and if you select one, it'll insert that choice.
I have added the script to the subversion repository (in the LaTeX bundle), incase anyone wishes to improve it (like not showing the dialog for a single match, handling “cancel” and zero matches (though which BibDesk doesn't seem to give) etc.).
Am 13.04.2005 um 03:21 schrieb Allan Odgaard:
Thanks for your quick and comprehensive reply!
I'm not exactly sure how BibDesk works -- it does install an input manager, but maybe this is to patch the NSTextView of the application, in which case it won't work with TM.
Ah, that's maybe it. Oh, well.
However, BibDesk does support AppleScript to lookup a search string for completion, so what you can do is go to menu Automation / Run Command / Edit Commands...
Make a new command with input: none, output: insert as snippet, key equivalent: option-escape and the actual command:
res=`osascript <<EOF tell application "Bibdesk" to set candidates to search for "$TM_CURRENT_WORD" with for completion tell application "System Events" activate choose from list candidates end tell EOF` osascript -e 'tell app "TextMate" to activate' &>/dev/null & echo -n ${res:${#TM_CURRENT_WORD}}
If you type something, press option-escape, it will lookup the word to the left of the caret, showing matches (from BibDesk) using an AS dialog, and if you select one, it'll insert that choice.
I have added the script to the subversion repository (in the LaTeX bundle), incase anyone wishes to improve it (like not showing the dialog for a single match, handling “cancel” and zero matches (though which BibDesk doesn't seem to give) etc.).
I changed this command a little to my needs for two reasons:
1. This works great if you type the beginning of the cite-key e.g. "Od" for "Odgaard2005" but if you type something from the title e.g. "Te" you'll get something like "Tegaard2005".
2. BibDesk gives the reference in the following format: "cite-key % author, title" e.g.
Odgaard2005 % Odgaard, TextMate - An insanely great new text editor
This is great as such when you want to chose the right item from the AS dialog, but when this string gets inserted, there's the problem that the ending brace from the \cite{} command will be uncommented thanks to BibDesk's percent sign which of course will give you trouble on the next LaTeX run. I could of course fix this by hand for every entry, but what do I have a computer for, I said to myself :-)
So, here goes: Input - Selected Text; Output - Replace Selected Text;
----
res=`osascript <<EOF tell application "Bibdesk" to set candidates to search for "$TM_SELECTED_TEXT" with for completion tell application "System Events" activate choose from list candidates end tell EOF` echo -n ${res} > /tmp/BibDesk_Completion.txt osascript -e 'tell app "TextMate" to activate' &>/dev/null & #perl -pe 's/ %/} %/' /tmp/BibDesk_Completion.txt cat /tmp/BibDesk_Completion.txt | awk '{print $1}' > /tmp/BibDesk_Completion.txt echo -n `cat /tmp/BibDesk_Completion.txt` ----
If I were a little more versatile with perl I would have actually gotten rid of everything except the cite-key but I couldn't so I used awk to do that for me. But maybe some kind soul out there is more savvy than me :-)
I also realize that creating the temporary file is a bit of kludge, but it's that versatility thing again :-)
Finally, I realize that having now to select the text is not as elegant as your solution but I don't see any other way if I want to use other bits than just the beginning of the cite key.
Anyways, thanks again for the quick reply and for TextMate, it really is insanely great! As for the above, maybe somebody will find this useful, I certainly do.
Best wishes, Thomas
On Apr 13, 2005, at 16:26, Thomas Schröder wrote:
I changed this command a little to my needs for two reasons:
- This works great if you type the beginning of the cite-key e.g.
"Od" for "Odgaard2005" but if you type something from the title e.g. "Te" you'll get something like "Tegaard2005".
Ah yes -- I didn't realize it was a sub-string search. What you could do is start the command like this:
if [[ -z $TM_SELECTED_TEXT ]] then phrase=$TM_CURRENT_WORD else phrase=$TM_SELECTED_TEXT fi
and then search for "$phrase", which will be current word when there is no selection. You'd need a similar 'if' construct when returning the result, so to cut the prefix when doing current word search.
- BibDesk gives the reference in the following format: "cite-key %
author, title" e.g.
I was indeed a bit puzzled by what it returned :)
echo -n ${res} > /tmp/BibDesk_Completion.txt osascript -e 'tell app "TextMate" to activate' &>/dev/null & #perl -pe 's/ %/} %/' /tmp/BibDesk_Completion.txt cat /tmp/BibDesk_Completion.txt | awk '{print $1}' > /tmp/BibDesk_Completion.txt echo -n `cat /tmp/BibDesk_Completion.txt`
Okay, here's my take on it:
osascript -e 'tell app "TextMate" to activate' &>/dev/null & awk <<<$res '{print $1}' | tr -d \n
Or if you want to keep the comment but insert a bracket: perl <<<$res -pe 's/^(\w+)/$1}/'
So the entire command (with the condition on selection) becomes: ----------8<---------- if [[ -z $TM_SELECTED_TEXT ]] then phrase=$TM_CURRENT_WORD else phrase=$TM_SELECTED_TEXT fi
res=`osascript <<EOF tell application "Bibdesk" to set candidates to search for "$phrase" with for completion tell application "System Events" activate choose from list candidates end tell EOF` osascript -e 'tell app "TextMate" to activate' &>/dev/null &
res=`perl <<<$res -pe 's/^(\w+)/$1}/'` if [[ -z $TM_SELECTED_TEXT ]] then echo -n ${res:${#TM_CURRENT_WORD}} else echo -n $res fi
Am 13.04.2005 um 23:10 schrieb Allan Odgaard:
On Apr 13, 2005, at 16:26, Thomas Schröder wrote:
- BibDesk gives the reference in the following format: "cite-key %
author, title" e.g.
I was indeed a bit puzzled by what it returned :)
:-)
Okay, here's my take on it:
osascript -e 'tell app "TextMate" to activate' &>/dev/null & awk <<<$res '{print $1}' | tr -d \n
Ah, great! OK, I think I'm starting to get the hang of this.
Or if you want to keep the comment but insert a bracket: perl <<<$res -pe 's/^(\w+)/$1}/'
That doesn't work for me because some of my cite-keys have appendixes like "-PVA" for a certain preparation method and the cite-key gets cut off at the "-". I prefer not to have the comments anyway, so I opt for the first version, so don't bother to fix this. At least not for me :-)
So the entire command (with the condition on selection) becomes: ----------8<---------- if [[ -z $TM_SELECTED_TEXT ]] then phrase=$TM_CURRENT_WORD else phrase=$TM_SELECTED_TEXT fi
res=`osascript <<EOF tell application "Bibdesk" to set candidates to search for "$phrase" with for completion tell application "System Events" activate choose from list candidates end tell EOF` osascript -e 'tell app "TextMate" to activate' &>/dev/null &
res=`perl <<<$res -pe 's/^(\w+)/$1}/'` if [[ -z $TM_SELECTED_TEXT ]] then echo -n ${res:${#TM_CURRENT_WORD}} else echo -n $res fi
Thanks for the effort, but I think I will stick with my new version which by the way incorporates your awk-pipe because that works better for me. Your new version does indeed handle things correctly for strings that are not part of the cite-key but only if you select the string, otherwise you still get a mix-up. For the time being this is too confusing for me even though the point still stands that it's way more elegant not to have to select some text. Anyways, here's my new take on this:
---
res=`osascript <<EOF tell application "Bibdesk" to set candidates to search for "$TM_SELECTED_TEXT" with for completion tell application "System Events" activate choose from list candidates end tell EOF`
osascript -e 'tell app "TextMate" to activate' &>/dev/null & awk <<<$res '{print $1}' | tr -d \n
---
As far as I'm concerned, everything works fine, I have what I wanted, so thank you very much!
Best wishes, Thomas