Browse Source

fix bugs with curly brackets

pull/63/merge
Martin Monperrus 9 years ago
parent
commit
0997e810c7
  1. 4
      bibtexbrowser-test.php
  2. 23
      bibtexbrowser.php

4
bibtexbrowser-test.php

@ -228,7 +228,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
function test_math_cal() { function test_math_cal() {
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
fwrite($test_data, "@book{aKey,title={{A Book $\mbox{foo}$ tt $\boo{t}$}} ,author={Martin Monperrus},publisher={Springer},year=2009}\n".
fwrite($test_data, "@book{aKey,title={{A {Book} $\mbox{foo}$ tt $\boo{t}$}} ,author={Martin Monperrus},publisher={Springer},year=2009}\n".
"@String{x=2008}\n" "@String{x=2008}\n"
); );
fseek($test_data,0); fseek($test_data,0);
@ -469,7 +469,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertEquals("Meyer, Heribert", $authors[0]); $this->assertEquals("Meyer, Heribert", $authors[0]);
$this->assertEquals("Advanced Air and Ground Research Team", $authors[1]); $this->assertEquals("Advanced Air and Ground Research Team", $authors[1]);
$this->assertEquals("Foo Bar", $authors[2]); $this->assertEquals("Foo Bar", $authors[2]);
$this->assertEquals("Jé Ko", $authors[3]);
$this->assertEquals("J{\'e} Ko", $authors[3]);
} }
function test_latex2html() { function test_latex2html() {

23
bibtexbrowser.php

@ -911,7 +911,7 @@ class BibDBBuilder extends ParserDelegate {
if ($this->currentEntry->hasField('author')) { if ($this->currentEntry->hasField('author')) {
$this->currentEntry->setField(Q_INNER_AUTHOR,$this->currentEntry->getFormattedAuthorsString()); $this->currentEntry->setField(Q_INNER_AUTHOR,$this->currentEntry->getFormattedAuthorsString());
foreach($this->currentEntry->split_authors() as $author) {
foreach($this->currentEntry->getCanonicalAuthors() as $author) {
$homepage_key = $this->currentEntry->getHomePageKey($author); $homepage_key = $this->currentEntry->getHomePageKey($author);
if (isset($this->stringdb[$homepage_key])) { if (isset($this->stringdb[$homepage_key])) {
$this->currentEntry->homepages[$homepage_key] = $this->stringdb[$homepage_key]->value; $this->currentEntry->homepages[$homepage_key] = $this->stringdb[$homepage_key]->value;
@ -1066,6 +1066,11 @@ function latex2html($line) {
$line = str_replace('\\k{a}','&#261',$line); $line = str_replace('\\k{a}','&#261',$line);
$line = str_replace('\\\'{c}','&#263',$line); $line = str_replace('\\\'{c}','&#263',$line);
// clean extra tex curly brackets, usually used for preserving capitals
// must come before the final math replacement
$line = str_replace('}','',$line);
$line = str_replace('{','',$line);
// we restore the math env // we restore the math env
for($i = 0; $i < count($maths); $i++) { for($i = 0; $i < count($maths); $i++) {
$line = str_replace('__MATH'.$i.'__', $maths[$i], $line); $line = str_replace('__MATH'.$i.'__', $maths[$i], $line);
@ -1204,10 +1209,6 @@ class BibEntry {
$value = mb_convert_encoding($value, OUTPUT_ENCODING, BIBTEX_INPUT_ENCODING); $value = mb_convert_encoding($value, OUTPUT_ENCODING, BIBTEX_INPUT_ENCODING);
} }
// clean extra tex curly brackets, usually used for preserving capitals
$value = $this->clean_top_curly($value);
} else { } else {
//echo "xx".$value."xx\n"; //echo "xx".$value."xx\n";
} }
@ -1414,19 +1415,19 @@ class BibEntry {
} }
function split_authors() { function split_authors() {
$array = preg_split('/ and /i', $this->getField(Q_AUTHOR));
$array = preg_split('/ and /i', @$this->raw_fields[Q_AUTHOR]);
$res = array(); $res = array();
// we merge the remaining ones // we merge the remaining ones
for ($i=0; $i < count($array)-1; $i++) { for ($i=0; $i < count($array)-1; $i++) {
if (strpos( latex2html($array[$i]), '{') !== FALSE && strpos(latex2html($array[$i+1]),'}') !== FALSE) {
$res[] = $this->clean_top_curly($array[$i]." and ".$array[$i+1]);
if (strpos( $array[$i], '{') !== FALSE && strpos($array[$i+1],'}') !== FALSE) {
$res[] = $this->clean_top_curly(trim($array[$i])." and ".trim($array[$i+1]));
$i = $i + 1; $i = $i + 1;
} else { } else {
$res[] = $array[$i];
$res[] = trim($array[$i]);
} }
} }
if (strpos($array[count($array)-1], '}')===FALSE) {
$res[] = $array[count($array)-1];
if (!preg_match('/^\}/',$array[count($array)-1])) {
$res[] = trim($array[count($array)-1]);
} }
return $res; return $res;
} }

Loading…
Cancel
Save