Last active
July 23, 2019 02:47
-
-
Save yohanesgultom/b75b15db414d2563027b76ce1be5ef8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latex guide and scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# latex ignored files | |
*.aux | |
*.glo | |
*.idx | |
*.log | |
*.toc | |
*.ist | |
*.acn | |
*.acr | |
*.alg | |
*.bbl | |
*.blg | |
*.dvi | |
*.glg | |
*.gls | |
*.ilg | |
*.ind | |
*.lof | |
*.lot | |
*.maf | |
*.mtc | |
*.mtc1 | |
*.out | |
*.synctex.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Parse BibTex entries from input file and render them in IEEEtran.cls format | |
# http://www.michaelshell.org/tex/ieeetran/ | |
# Usage: python bibtexconverter.py [bibtex file] | |
# | |
# BibTex example (input): | |
# @article{lecun2015deep, | |
# title={Deep learning}, | |
# author={LeCun, Yann and Bengio, Yoshua and Hinton, Geoffrey}, | |
# journal={Nature}, | |
# volume={521}, | |
# number={7553}, | |
# pages={436--444}, | |
# year={2015}, | |
# publisher={Nature Publishing Group} | |
# } | |
# | |
# IEEETran example (output): | |
# \bibitem{lecun2015deep} Y.~LeCun and Y.~Bengio and G.~Hinton, \emph{Deep learning}.\hskip 1em plus 0.5em minus 0.4em\relax Nature, Nature Publishing Group, 2015. | |
import re | |
import sys | |
from pprint import pprint | |
def ieee(refs): | |
print '\n' | |
for ref in refs: | |
print _ieee(ref) + '\n' | |
def _ieee(dic): | |
return """\\bibitem{{{}}} {}, \\emph{{{}}}.\\hskip 1em plus 0.5em minus 0.4em\\relax {}, {}.""".format( | |
dic['refcode'], | |
_ieee_author(dic['author']), | |
dic['title'], | |
_ieee_publisher(dic), | |
dic['year'] | |
) | |
def _ieee_publisher(dic): | |
publisher = [] | |
keys = ['journal', 'booktitle', 'publisher', 'organization'] | |
for key in keys: | |
if key in dic: | |
publisher.append(dic[key]) | |
return ', '.join(publisher) | |
def _ieee_author(text): | |
formatted = [] | |
authors = text.split(' and ') | |
for a in authors: | |
names = a.split(', ') | |
if len(names) >= 2: | |
last, first = names[0], names[1] | |
formatted.append(first[0].upper() + '.~' + last) | |
else: | |
formatted.append(names[0]) | |
return ' and '.join(formatted) | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
print 'Usage: python bibtexconverter.py [bibtex file]' | |
exit() | |
filename = sys.argv[1] | |
# collect BibTex entries from input file | |
# separated by blank line | |
entries = [] | |
with open(filename) as f: | |
entry = [] | |
for line in f: | |
line = line.strip() | |
if len(line) > 0: | |
# save line | |
entry.append(line) | |
elif len(entry) > 0: | |
# blank line | |
entries.append(entry) | |
entry = [] | |
# last entry | |
if len(entry) > 0: | |
entries.append(entry) | |
# parse BibTex entries | |
references = [] | |
for entry in entries: | |
dic = {} | |
dic['refcode'] = re.search(r'@(article|inproceedings|thesis){([\w\d]*),', entry[0], re.M | re.I).group(2) | |
for i in range(1, (len(entry) - 1)): | |
key, value = entry[i].split('=') | |
value = re.search(r'{([^{}]*)}', value, re.M | re.I).group(1) | |
dic[key] = value | |
references.append(dic) | |
# render entries in IEEEtran.cls format | |
# http://www.michaelshell.org/tex/ieeetran/ | |
ieee(references) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Converting latex to docx | |
# sudo apt install pandoc pandoc-citeproc | |
echo "converting to docx.." | |
pandoc -f latex -t docx -o $2 --bibliography ../references.bib $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compiling IEEETran template in Debian/Ubuntu using TexStudio | |
# Install TexStudio and mandatory packages | |
sudo apt install texstudio texlive-fonts-recommended texlive-publishers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copied from https://gist.github.com/dougalsutherland/266983/9c88f1ca1cf1420af03166dcfccb9cb10a21c110 | |
#!/bin/bash | |
exts=".aux .lof .log .lot .fls .out .toc .dvi .bbl .bcf .blg -blx.aux -blx.bib -blx.bib .run.xml .fdb_latexmk .synctex.gz .syntex.gz(busy) .pdfsync .algorithms .alg .loa .thm .nav .snm .vrb .acn .acr .glg .glo .gls .brf .lol .idx .ilg .ind .ist .maf .mtc .mtc0 .pyg .nlo .tdo .xdy .keys" | |
for x in "${@:-.}"; do | |
arg=$(echo ${x:-.} | perl -pe 's/\.(tex|pdf)$//') | |
if [[ -d "$arg" ]]; then | |
for ext in $exts; do | |
rm -f "$arg"/*$ext | |
done | |
else | |
for ext in $exts; do | |
rm -f "$arg"$ext | |
done | |
fi | |
done | |
rm -rf $(biber --cache) # gross biber bug |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment