fix math expression problems
This commit is contained in:
+15
-1
@@ -141,7 +141,7 @@ class BibtexbrowserTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
// IEEE style
|
// IEEE style
|
||||||
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle');
|
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle');
|
||||||
$this->assertEquals("Foo Bar and Jane Doe, \"An Article\", In New Results, vol. 5, pp. 1-2, 2009.\n ",strip_tags($first_entry->toHTML()));
|
$this->assertEquals("Foo Bar and Jane Doe, \"An Article\", New Results, vol. 5, pp. 1-2, 2009.\n ",strip_tags($first_entry->toHTML()));
|
||||||
$css_classes_after = $this->extract_css_classes($first_entry->toHTML());
|
$css_classes_after = $this->extract_css_classes($first_entry->toHTML());
|
||||||
// contract: make sure the Janos style and default style use the same CSS classes
|
// contract: make sure the Janos style and default style use the same CSS classes
|
||||||
$this->assertEquals($css_classes_before, $css_classes_after);
|
$this->assertEquals($css_classes_before, $css_classes_after);
|
||||||
@@ -847,6 +847,20 @@ class BibtexbrowserTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_uppercase() {
|
||||||
|
print(preg_replace_callback('/\\\\uppercase\{(.*)\}/',"strtolowercallback", "$\uppercase{B}"));
|
||||||
|
|
||||||
|
$bibtex = "@article{doe2000,title={Preferential polarization and its reversal in polycrystalline $\uppercase{B}i\uppercase{F}e\uppercase{O}_{3}$/$\uppercase{L}a_{0. 5}\uppercase{S}r_{0.5} \uppercase{C}o\uppercase{O}_{3}$ heterostructures},author={Jane Doe},journal={The Wordpress Journal},year=2000}";
|
||||||
|
$test_data = fopen('php://memory','x+');
|
||||||
|
fwrite($test_data, $bibtex);
|
||||||
|
fseek($test_data,0);
|
||||||
|
$db = new BibDataBase();
|
||||||
|
$_GET[Q_FILE] = 'sample.bib';
|
||||||
|
$db->update_internal("inline", $test_data);
|
||||||
|
$this->assertEquals('Preferential polarization and its reversal in polycrystalline $BiFeO_{3}$/$La_{0. 5}Sr_{0.5} CoO_{3}$ heterostructures', $db->bibdb['doe2000']->getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // end class
|
} // end class
|
||||||
|
|
||||||
|
|||||||
+28
-7
@@ -997,6 +997,21 @@ function latex2html($line, $do_clean_extra_bracket=true) {
|
|||||||
// added && strpos($line,'{')===false
|
// added && strpos($line,'{')===false
|
||||||
if (strpos($line,'\\')===false && strpos($line,'{')===false) return $line;
|
if (strpos($line,'\\')===false && strpos($line,'{')===false) return $line;
|
||||||
|
|
||||||
|
// handling uppercase
|
||||||
|
// echo preg_replace_callback('!\b[a-z]!', 'upper', strtolower($str));
|
||||||
|
if (!function_exists("strtolowercallback")) {
|
||||||
|
function strtolowercallback($array) {
|
||||||
|
return strtolower($array[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!function_exists("strtouppercallback")) {
|
||||||
|
function strtouppercallback($array) {
|
||||||
|
return strtoupper($array[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$line = preg_replace_callback('/\\\\uppercase\{(.*)\}/U',"strtouppercallback", $line);
|
||||||
|
$line = preg_replace_callback('/\\\\lowercase\{(.*)\}/U',"strtolowercallback", $line);
|
||||||
|
|
||||||
$maths = array();
|
$maths = array();
|
||||||
$index = 0;
|
$index = 0;
|
||||||
// first we escape the math env
|
// first we escape the math env
|
||||||
@@ -1087,6 +1102,8 @@ function latex2html($line, $do_clean_extra_bracket=true) {
|
|||||||
// handling \textsubscript{....} FAILS if there still are nested {}
|
// handling \textsubscript{....} FAILS if there still are nested {}
|
||||||
$line = preg_replace('/\\\\textsubscript\{(.*)\}/U','<sub>\\1</sub>', $line);
|
$line = preg_replace('/\\\\textsubscript\{(.*)\}/U','<sub>\\1</sub>', $line);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($do_clean_extra_bracket) {
|
if ($do_clean_extra_bracket) {
|
||||||
// clean extra tex curly brackets, usually used for preserving capitals
|
// clean extra tex curly brackets, usually used for preserving capitals
|
||||||
// must come before the final math replacement
|
// must come before the final math replacement
|
||||||
@@ -2452,7 +2469,7 @@ function JanosBibliographyStyle($bibentry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($type=="article" && $bibentry->hasField("journal")) {
|
if ($type=="article" && $bibentry->hasField("journal")) {
|
||||||
$booktitle = '<span class="bibbooktitle">'.'In '.$bibentry->getField("journal").'</span>';
|
$booktitle = '<span class="bibbooktitle">'.''.$bibentry->getField("journal").'</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2774,12 +2791,16 @@ $('a.biburl').each(function() { // for each url "[bibtex]"
|
|||||||
if (!function_exists('javascript_math')) {
|
if (!function_exists('javascript_math')) {
|
||||||
function javascript_math() {
|
function javascript_math() {
|
||||||
?>
|
?>
|
||||||
<script type="text/x-mathjax-config">
|
<script>
|
||||||
MathJax.Hub.Config({
|
MathJax = {
|
||||||
tex2jax: {inlineMath: [["$","$"]]}
|
tex: {
|
||||||
});
|
inlineMath: [['$', '$'], ['\\(', '\\)']]
|
||||||
</script>
|
}
|
||||||
<script src="<?php echo MATHJAX_URI ?>"></script>
|
};
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript" id="MathJax-script" async
|
||||||
|
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
|
||||||
|
</script>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user