In bibtex, one uses curly brackets to protect capitalization – so that, for example, {3D} or {DNA} or {BioSysComp} won't turn into 3d or dna or biosyscomp.

I think these brackets should stay in the database as they are imported, but when displaying titles, I believe they could be removed... curly brackets are extremely rarely used in titles so removing them (only for display) would improve the look of bibliographies.

Comments

rene_w’s picture

subscribing

Frank Steiner’s picture

This problem is not trivial and has been discussed some times before. biblio uses the normal node title for the publication title, and the node title can be used at so many different places from so many different modules that you cannot keep the brackets in there. So I guess one would need to have an additional biblio_title field to store the (imported or entered) title with brackets while still using node->title for the unbracketed version.

We currently embrace the whole title when exporting (via our famous bibtex hook ;-)) so that the title is at least saved as a whole.

Ron, do you think that using an additional biblio->bibtex-title or similar could be a solution?

rene_w’s picture

From my (end user's) perspective, it's important to have round-trip support for bibtex files. I work with LaTeX, so I need to get the exact same bibtex out of Biblio that I put in, which includes quirks like the {} thing in title/booktitle.

I suppose a separate node-title could work, but then there's a new problem in that changes to one of the titles must be reflected in the other (lest you end up with two different titles for the same entry). Presenting only the bibtex title (braces and all) for editing and automatically deriving the node title from it could work.

Note that there are also math-mode braces in BibTeX titles ("My {$\srqt{\pi^2}$} cents"}, but I image that'll be even more difficult to handle unless you embed tex4ht or somesuch.

rjerome’s picture

I'd say it's pretty hard to guarantee round trip support, mainly because we are not dealing only with bibtex data. One way might be to simply put a filter in which would remove any remaining {} when the node is displayed but they would remain in the database so on export they should still be in the export data file.

Frank Steiner’s picture

I tried this once but one will fail to handle at least the node title because an input filter doesn't apply to the title. And so you will see it in any views application and I don't know where else. However, this might be a minor drawback that one might be able to live with.

Tecktron’s picture

[Subscribing]

I agree that this would be great for display purposes only, so that when it's exported it comes directly from the DB where it's stored correctly.
I'd do something along the lines of a preg_replace_callback to simply remove them.
I'll work on the function with a regex and callback so it removes the {} from any string you pass to it, eg:

"This is {CAPITAL} {T}ext in {3D}!" would become simply "This is CAPITAL Text in 3D!"

Then all someone has to do would be to implementing the function where it needs to go =)

Would also be cool and convenient for an option to turn the feature on or off in the admin menu.
Something like: ($remBraceOpt==TRUE)?remBraceFunc($title_string):$title_string;

Would be a nice feature in my opinion. Expect something from me soon.

Thanks,
--Craig

masood_mj’s picture

subscribing
would you help me to write a sql query to remove { } from biblio tables?

Tecktron’s picture

So this takes in a string and removes the braces. The idea is this would be on a db pull and display, but never for saving into the db (you want the braces for export). I've made it so it ignores {$...$} in order to save any math notation. Give it a spin and let me know what you think.

OK Here is the code for the functions:

function remBraceFunc($title_string){
	$title_string=utf8_encode($title_string);
	$matchpattern='/\{\$(?:(?!\$\}).)*\$\}|(\{[^}]*\})/';
	$output=preg_replace_callback($matchpattern,'remBraceFromMatch',$title_string);
	return $output;
}

function remBraceFromMatch($match){
        if(isset($match[1])){
                $braceless=str_replace('{','',$match[1]);
                $braceless=str_replace('}','',$braceless);
                return $braceless;
        }
        return $match[0];
}

$displayOutput=remBraceFunc($title_string);

Now it just needs to be implemented into the hook... Interested Ron? Anybody?

Thanks,
--Craig

rjerome’s picture

Thanks Craig,

I thought maybe I could use hook_nodeapi and the "view" op to achieve this, and it almost works but the page title seems to get rendered prior to this being called so the braces still show up in the page title.

I'll dig around a bit more, but we're close.

Ron.

Tecktron’s picture

Ron,

I've been looking through this a bit (and slowly coming to grasps with Drupal), and I think that "load" case of the nodeapi would work. That's what I see some of the page title modules use (beyond that part I'm lost, but still learning). Maybe give that a shot.

Thanks,
--Craig

rjerome’s picture

I did try that but the problem with "load" is that it's too early in the process, so if you edit the node, the you will see that the braces are gone, then if you save it the braces will be gone for good. The problem with view is it's just a little too late in the render process so the node "contents/body" are OK, but the title is rendered prior to calling nodeapi with the "view" op so the page title still has the braces.

I just came up with the solution, which is sort of a hybrid, the braces are stripped off in hook_view and then drupal_set_title is called in hook_nodeapi (op == 'view') to reset the title to the braceless version. Using this method, the braces are save in the database, and you will see them when you edit the node but they are not displayed.

Tecktron’s picture

Brilliant!
Thanks!

I can't wait to see it in action!

--Craig

rjerome’s picture

No need to wait Craig, you can try it now in the -dev version...

Ron.

nschloe’s picture

subscribing

rjerome’s picture

In case you were wondering Nico, this feature is in the 1.6 version.

Ron.

nschloe’s picture

Hm, unconfirmed. -- I'm still getting the issue with 1.6; see, for example, the file at http://drupal.org/node/584616#comment-2088188.

Cheers,
Nico

rene_w’s picture

Version: master » 6.x-1.14

Here are some places where I noticed the bibtex braces still showing up (they are already filtered out in the node and list views):

  • in search results
  • in the "most recent publications" block
  • in the "Similar entries from ANY vocabulary" block (same as search?)
  • in the exported files (RTF, Tagged, XML -- obviously in Bibtex export they are ok)
rjerome’s picture

I've dealt with

  • in the "most recent publications" block
  • in the exported files (RTF, Tagged, XML -- obviously in Bibtex export they are ok)

The search related ones are going to be a problem though because I haven't yet found a way for the module to modify the search results prior to the system displaying them.

rjerome’s picture

Ok, so I have a new plan for this {Protected} capitalization of titles issue...

In the 6.x-2.x version of the module, each of the import/export types has been made into a separate module which maintains it's own table in the database. So the plan for BibTex is to stick the title with {} included in the biblio_bibtex table, and then strip the {}'s out an store that where the title normally goes in the node table. This way searches and the like will see the sanitized version and when exporting in BibTex format, I'll just substitute the title from the biblio_bibtex table. This also has the benefit of me not having to sanitize the title all over the place.

Ron.

rene_w’s picture

Sounds good, but: Would it then still be possible to _enter_ the protected titles when not importing from bibtex (i.e. entering a publication via the web form)?

rene_w’s picture

Addendum: The braces also show up in

  • biblio citations (<bib>) and
  • inline citations (<ibib>)
rene_w’s picture

Regarding the separate bibtex-title field: as mentioned earlier (http://drupal.org/node/314488#comment-1361860) it would need to be editable, to allow changes in the title field being reflected in the bibtex-title field (and vice versa).

Here's what I would suggest:

  • Add a separate bibtex-title field, which is editable like any other field, just below the title field (maybe allow to hide it via an option for users who don't care about BibTeX)
  • When importing from bibtex, store the raw title in the bibtex-title and derive the title field by removing the braces (like it is done now when displaying bibtex titles)
  • When exporting to bibtex, use the bibtex-title field if it is non-empty, otherwise use the title field
  • For all other places where a title is shown, just use the title field

Having a separate bibtex-title has some additional benefits, for example, we can have a bibtex-title called "{My $x^{2}$ Cents}" but display the nicer title "My x² Cents"; plus it gets rid of all the special cases handling the braces. We now effectively ask the user to take care of it, which seems reasonable to me.

rjerome’s picture

I think it will be easier to handle all of this BibTex stuff since it is in a separate module any we can use the nodeapi hook to do this cleanup when the module is enabled.

megic’s picture

I'd like to work with a stable version of biblio and just came accross the {Protected} problem in the title.

Just wanted to ask what my options are:
-) Correcting the {} manually or through the database
-) Using a dev version (which one?)

Is there a another/better option?

rjerome’s picture

You could try the 6.x-1.x-dev version, I believe that issue has be fixed in that version (and you can always switch back to the release version when the next one comes out).

Ron.

shaundychko’s picture

Version: 6.x-1.14 » 6.x-1.15

putting the following in template.php of your theme removes braces from the main title for each search result (but not the search result subtext...). Adjust [theme-name] accordingly.

function [theme-name]_preprocess_search_result(&$variables) {
  if ($variables[result][node]->type == 'biblio' &&
      variable_get('biblio_hide_bibtex_braces', 0)) {
    $variables['title'] = biblio_remove_brace($variables['title']);
  }
}
liam morland’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

This version is no longer maintained. If this issue is still relevant to the Drupal 7 version, please re-open and provide details.