Prechádzať zdrojové kódy

fix some bib issues

Daniel Gruss 2 rokov pred
rodič
commit
76b17c2bea
2 zmenil súbory, kde vykonal 73 pridanie a 59 odobranie
  1. 11 3
      main.tex.php
  2. 62 56
      thesiscomposer.php

+ 11 - 3
main.tex.php

@@ -16,10 +16,12 @@
 
 \usepackage{tugraz_defaults}
 \addbibresource{main.bib}
+% TODO: if you have unused bib files lying around, some of theses might be incorrectly added:
 <?php 
-foreach ($bibresources as $br => $bib)
+foreach ($bibresources as $biblist)
 {
-  echo '\addbibresource{'.$bib.'}
+  foreach ($biblist as $bib)
+    echo '\addbibresource{'.$bib.'}
 ';
 }
 if (isset($options["--cv"]))
@@ -142,7 +144,13 @@ if (isset($options["--cv"]))
 During my thesis, I contributed to <?php echo $num_publications ?> publications in conference proceedings, <?php echo $num_publications_in_thesis ?> of which are included in this thesis as shown below.
 
 \newrefcontext[sorting=ydnt]
-\nocite{CV:*}
+
+<?php 
+if (isset($options['--cv']))
+{
+echo '\nocite{CV:*}';
+}
+?>
 
 <?php echo $sloppy_begin; ?>
 \printbibliography[title={Publications in this Thesis}, type=inproceedings, heading=subbibliography, keyword={mine}]

+ 62 - 56
thesiscomposer.php

@@ -268,14 +268,15 @@ END;
         if (str_ends_with($file,".bib"))
         {
           $bib = file_get_and_backup($file);
+          $bib = str_replace('\`','\\\'',$bib);
           $bib = preg_replace("/(^\s*@\s*[a-z]+\s*\{\s*)((?!$d)\S)/i",'${1}'.$d.':${2}',$bib);
           $bib = preg_replace("/(\n\s*@\s*[a-z]+\s*\{\s*)((?!$d)\S)/i",'${1}'.$d.':${2}',$bib);
           $bib = preg_replace("/([\{\"].*)[^\\\\]#(.*)/i",'${1}\#${2}',$bib);
-          $bib = str_replace('{\i}','{i}',$bib);
+          $bib = str_replace('\i}','i}',$bib);
           $bib = str_replace('$\textregistered$','\textregistered',$bib);
           $bib = str_replace('{$\textquoteright$}','\'',$bib);
           file_put_contents($file,$bib);
-          $bibresources[$d] = $file;
+          $bibresources[$d][] = $file;
         }
         else
         {
@@ -527,7 +528,6 @@ END;
         $tikzlibs[] = $v;
       }
 
-
       $tex = preg_replace("/\\\\documentclass{iacrtrans}/i","\declarecommand{\inst}[1]{\\textsuperscript{#1}}",$tex);
       $tex = preg_replace("/\\\\documentclass.*\\n/i","
 ",$tex);
@@ -546,45 +546,6 @@ END;
         $tex = preg_replace("/\\\\begin{document}/i",$header,$tex);
         $header = "";
       }
-      $tex = preg_replace("/\\\\begin{acks}/i","\section*{Acknowledgements}",$tex);
-      $tex = preg_replace("/\\\\end{acks}/i","",$tex);
-      $tex = preg_replace("/\\\\(re)?newcommand/i",'\declarecommand',$tex);
-      $tex = preg_replace("/\\\\DeclareRobustCommand\s*(?<R>{((?:[^{}]+|(?&R))*)})\s*(?<Q>{((?:[^{}]+|(?&Q))*)})/i",'',$tex);
-      $tex = preg_replace("/\\\\(re)?newenvironment/i",'\declareenvironment',$tex);
-      $tex = preg_replace("/\\\\(Re)?NewDocumentEnvironment/i",'\DeclareDocumentEnvironment',$tex);
-      $tex = preg_replace("/\\\\end{abstract}/i",'',$tex);
-      $tex = preg_replace("/\\\\onecolumn/i",'',$tex);
-      $tex = preg_replace("/\\\\(begin|end){(IEEEkeywords|CCSXML)}/i",'\$1{comment}',$tex);
-      $tex = preg_replace("/\\\\pagenumbering\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\special\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\DeclareMathOperator/i",'%$0',$tex);
-      $tex = preg_replace("/\\\\DeclareMathAlphabet/i",'%$0',$tex);
-      $tex = preg_replace("/\\\\usepackage\s*(\[[^\[\]]*\])?\s*{minted}/i",'\usepackage{minted}',$tex);
-      $tex = preg_replace("/\\\\thispagestyle{empty}/i",'%$0',$tex);
-      $tex = preg_replace("/\\\\PassOptionsToPackage\s*(?<R>{((?:[^{}]+|(?&R))*)})(?<Q>{((?:[^{}]+|(?&Q))*)})/i",'',$tex);
-      $tex = preg_replace("/(\\\\csvautobooktabular\s*([^{}]*)\s*)(?<R>{((?:[^{}]+|(?&R))*)})/i","\\1{{$d}/\\4}",$tex);
-      $tex = preg_replace("/\\\\AtBeginDocument\s*(?<R>{((?:[^{}]+|(?&R))*)})/i",'',$tex);
-      $tex = preg_replace("/\\\\bibliographystyle\s*(?<R>{((?:[^{}]+|(?&R))*)})/i",'%$0',$tex);
-      $tex = preg_replace("/\\\\usetikzlibrary\s*(?<R>{((?:[^{}]+|(?&R))*)})/i",'%$0',$tex);
-      $tex = preg_replace("/\\\\DeclareFloatFont\s*(?<R>{((?:[^{}]+|(?&R))*)})(?<Q>{((?:[^{}]+|(?&Q))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\captionsetup\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])?(?<Q>{((?:[^{}]+|(?&Q))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\RequirePackage\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])?(?<Q>{((?:[^{}]+|(?&Q))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\ccsdesc\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])?(?<Q>{((?:[^{}]+|(?&Q))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\tikzexternalize\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])/i","",$tex);
-      $tex = preg_replace("/\\\\floatsetup\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])(?<Q>{((?:[^{}]+|(?&Q))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\newfloat\s*(?<R>{((?:[^{}]+|(?&R))*)})(?<Q>{((?:[^{}]+|(?&Q))*)})(?<P>{((?:[^{}]+|(?&P))*)})/i","",$tex);
-      global $sloppy_begin;
-      global $sloppy_end;
-      $tex = preg_replace("/\s*\\\\bibliography\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","\n".$sloppy_begin.'
-\printbibliography[title={References}, heading=subbibliography]
-'.$sloppy_end,$tex);
-      $tex = preg_replace("/\\\\end{document}/i",'',$tex);
-      $tex = preg_replace("/\n\s*\\\\author\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\tag\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\n\s*\\\\authorrunning\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\n\s*\\\\institute\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\n\s*\\\\title\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\n\s*\\\\date\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
       $graphicspath = "";
       preg_match("/\\\\graphicspath\s*(?<R>{((?:[^{}]+|(?&R))*)})/i",$tex,$matches);
       if (count($matches) > 3)
@@ -592,27 +553,72 @@ END;
       if (count($matches) > 3)
         $graphicspath = $matches[2];
       $tex = preg_replace("/\\\\includegraphics\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])(?<Q>{((?:[^{}]+|(?&Q))*)})/i",'\includegraphics${1}{'.$d."/".$graphicspath.'${4}}',$tex);
-      $tex = preg_replace("/\\\\IEEEoverridecommandlockouts/i","",$tex);
-      $tex = preg_replace("/\\\\IEEEauthorblock[AN]/i","",$tex);
-      $tex = preg_replace("/\\\\IEEEauthorrefmark/i","\\textsuperscript",$tex);
-      $tex = preg_replace("/\\\\twocolumn/i","",$tex);
-      $tex = preg_replace("/\\\\copyrightyear\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\setcopyright\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\settopmatter\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\acmYear\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\email\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      global $sloppy_begin;
+      global $sloppy_end;
+      $tex = preg_replace("/\s*\\\\bibliography\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","\n".$sloppy_begin.'
+\printbibliography[title={References}, heading=subbibliography]
+'.$sloppy_end,$tex);
+      $tex = preg_replace("/\\\\begin{thebibliography}/i","\n".$sloppy_begin.'
+\printbibliography[title={References}, heading=subbibliography]
+'.$sloppy_end."\n$0",$tex);
+
+      $tex = preg_replace("/(\\\\begin|end){(IEEEkeywords|CCSXML|thebibliography)}/i",'$1{comment}',$tex);
+      $tex = preg_replace("/(\\\\csvautobooktabular\s*([^{}]*)\s*)(?<R>{((?:[^{}]+|(?&R))*)})/i","\\1{{$d}/\\4}",$tex);
+      $tex = preg_replace("/\\\\(re)?newcommand/i",'\declarecommand',$tex);
+      $tex = preg_replace("/\\\\(Re)?NewDocumentEnvironment/i",'\DeclareDocumentEnvironment',$tex);
+      $tex = preg_replace("/\\\\(re)?newenvironment/i",'\declareenvironment',$tex);
       $tex = preg_replace("/\\\\acmBooktitle\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\acmPrice\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\acmConference\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])?\s*(?<Q>{((?:[^{}]+|(?&Q))*)})\s*(?<X>{((?:[^{}]+|(?&X))*)})\s*(?<Y>{((?:[^{}]+|(?&Y))*)})/i","",$tex);
       $tex = preg_replace("/\\\\acmDOI\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
       $tex = preg_replace("/\\\\acmISBN\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\fancyhead\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\acmPrice\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\acmYear\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
       $tex = preg_replace("/\\\\affiliation\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\acmConference\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])?\s*(?<Q>{((?:[^{}]+|(?&Q))*)})\s*(?<X>{((?:[^{}]+|(?&X))*)})\s*(?<Y>{((?:[^{}]+|(?&Y))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\SetWatermarkText\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\AtBeginDocument\s*(?<R>{((?:[^{}]+|(?&R))*)})/i",'',$tex);
+      $tex = preg_replace("/\\\\begin{acks}/i","\section*{Acknowledgements}",$tex);
+      $tex = preg_replace("/(\\\\bibitem\s*)(?<R>{((?:[^{}]+|(?&R))*)})/i",'$1{'.$d.':$3}',$tex);
+      $tex = preg_replace("/\\\\bibliographystyle\s*(?<R>{((?:[^{}]+|(?&R))*)})/i",'%$0',$tex);
+      $tex = preg_replace("/\\\\captionsetup\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])?(?<Q>{((?:[^{}]+|(?&Q))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\ccsdesc\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])?(?<Q>{((?:[^{}]+|(?&Q))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\copyrightyear\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\DeclareFloatFont\s*(?<R>{((?:[^{}]+|(?&R))*)})(?<Q>{((?:[^{}]+|(?&Q))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\DeclareMathAlphabet/i",'%$0',$tex);
+      $tex = preg_replace("/\\\\DeclareMathOperator/i",'%$0',$tex);
+      $tex = preg_replace("/\\\\DeclareRobustCommand\s*(?<R>{((?:[^{}]+|(?&R))*)})\s*(?<Q>{((?:[^{}]+|(?&Q))*)})/i",'',$tex);
+      $tex = preg_replace("/\\\\email\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\end{abstract}/i",'',$tex);
+      $tex = preg_replace("/\\\\end{acks}/i","",$tex);
+      $tex = preg_replace("/\\\\end{document}/i",'',$tex);
+      $tex = preg_replace("/\\\\fancyhead\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\floatsetup\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])(?<Q>{((?:[^{}]+|(?&Q))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\IEEEauthorblock[AN]/i","",$tex);
+      $tex = preg_replace("/\\\\IEEEauthorrefmark/i","\\textsuperscript",$tex);
+      $tex = preg_replace("/\\\\IEEEoverridecommandlockouts/i","",$tex);
+      $tex = preg_replace("/\\\\newfloat\s*(?<R>{((?:[^{}]+|(?&R))*)})(?<Q>{((?:[^{}]+|(?&Q))*)})(?<P>{((?:[^{}]+|(?&P))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\onecolumn/i",'',$tex);
+      $tex = preg_replace("/\\\\pagenumbering\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\PassOptionsToPackage\s*(?<R>{((?:[^{}]+|(?&R))*)})(?<Q>{((?:[^{}]+|(?&Q))*)})/i",'',$tex);
       $tex = preg_replace("/\\\\ProvidesPackage\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
-      $tex = preg_replace("/\\\\SetWatermarkScale\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\RequirePackage\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])?(?<Q>{((?:[^{}]+|(?&Q))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\setcopyright\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\settopmatter\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
       $tex = preg_replace("/\\\\SetWatermarkLightness\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\SetWatermarkScale\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\SetWatermarkText\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\special\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\tag\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\\\\thispagestyle{empty}/i",'%$0',$tex);
+      $tex = preg_replace("/\\\\tikzexternalize\s*(?<R>\[((?:[^\[\]]+|(?&R))*)\])/i","",$tex);
+      $tex = preg_replace("/\\\\twocolumn/i","",$tex);
+      $tex = preg_replace("/\\\\usepackage\s*(\[[^\[\]]*\])?\s*{minted}/i",'\usepackage{minted}',$tex);
+      $tex = preg_replace("/\\\\usetikzlibrary\s*(?<R>{((?:[^{}]+|(?&R))*)})/i",'%$0',$tex);
+      $tex = preg_replace("/\n\s*\\\\author\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\n\s*\\\\authorrunning\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\n\s*\\\\date\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+      $tex = preg_replace("/\n\s*\\\\institute\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
       $tex = preg_replace("/\n\s*\\\\tikzexternalize/i","",$tex);
+      $tex = preg_replace("/\n\s*\\\\title\s*(?<R>{((?:[^{}]+|(?&R))*)})/i","",$tex);
+
       [$ups,$ps] = getusepackages($tex);
       global $ignore_packages;
       global $included_usepackages;