0

I'm rather new to this and I'm trying to modify the standard plainurl bst file to add other links on top of the usual ones (arxiv/doi/pubmed/url).

By mimicking exactly what appears in the file I'm able to do so, but the preprint server I'd like to resolve needs a final '/' on the url otherwise the page appears to be non-existent.

Specifically, other than the pieces I had to define in ENTRY, STRINGS etc. needed, I have

FUNCTION {format.newserver}
{ newserver empty$
    { "" }
    { newserverprefix number * newserverurl number * make.href }
  if$
}

which in the bibliography prints me newserverprefix:number hyperreff'ed to http://newserverurl/number.

I would like to be it hyperreff'ed to "http://newserverurl/number/". How can I achieve it?

3
  • Welcome! Since you didn't add a compilable example it's hard to test anything. However try adding "/" * after make.href...
    – LaTeXer
    Commented Oct 4, 2019 at 11:16
  • Thanks for the reply. I was indeed able to fix it doing exactly like you suggested - I just had problems with how the * works. Now I wrapped my head around!
    – Giorgio
    Commented Oct 4, 2019 at 14:56
  • My previous suggestion was not correct. I wrote an answer with a better suggestion and an explantion.
    – LaTeXer
    Commented Oct 4, 2019 at 15:53

1 Answer 1

2

Without a proper example to test it is hard to say anything for sure, but if all you want to do is to add a trailing /, then you can use "/" * after newserverprefix number * to add to the printed text and/or after newserverurl number * to add to the actual URL:

FUNCTION {format.newserver}
{ newserver empty$
    { "" }
    { newserverprefix number * "/" * % This adds / to the printed text
         newserverurl number * "/" * % This adds / to the actual URL
      make.href }
  if$
}

An explanation:

The BibTeX language usees Reverse Polish Notation (RPN), or Postfix Notation, which means that you add items to a stack, and then use operators to do something on that stack.

The format.newserver function adds newserver to the stack and then uses the empty$ function. This function will test if the topmost item of the stack is empty (what a surprise!) and will leave the result on the top of the stack.

The function then adds two more items to the stack: "" and newserverprefix number * newserverurl number * make.href, and then uses the if$ function. This function will take three items from the top of the stack and checks if the third (top-down) is true. If so, the second item is put back on the stack, otherwise the first.

In case the newserver is empty, the function returns "", so we know that the entire function should only return a string. In case newserver isn't empty, then newserverprefix number * newserverurl number * make.href is used.

That sequence puts newserverprefix and number on the stack and concatenates both strings with *. It then puts newserverurl and number on the stack and concatenates these with *. Then make takes the topmost two items on the stack and writes the URL. The second item (top-down) is the text to be printed, and the first item is the actual URL.

So to add a trailing / you need to add another item to the stack, the string "/", and concatenate it with the URL text and/or the URL with a *:

newserverprefix % add newserverprefix 
number          % add number
*               % concatenate
"/"             % add "/"
*               % concatenate
newserverurl    % add newserverurl
number          % add number
*               % concatenate
"/"             % add "/"
*               % concatenate
make.href       % make the hyper-reference

You must log in to answer this question.

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