Tuesday, March 3, 2015

git commands

To set up a new git repo with existing project:
cd .../project
edit .gitignore
git init
git add . -v
git commit

Add repo to bitbucket:
Create repository here: https://bitbucket.org/repo/create
git remote add origin https://user@bitbucket.org/user/project.git
git push -u origin --all
git push -u origin --tags

important concepts in git: the working tree (files on disk), the index (the staging area for the next commit), and HEAD (last commit you made)

to add new file to index OR to get a changed file to the index:
git add whatever.tex
(this does not commit the new file)
to add all changes and new files (but not rm anything) (-v for verbose):
git add -v .

to commit (will prompt for commit message):
git commit

push to github/bitbucket:
git push origin master
to push all branches/tags:
git push --all
git push --tags

diff between working copy and index:
git diff
diff between index and HEAD:
git diff --cached
diff between local (HEAD?) and github:
git diff origin/master master

status:
git status
abbreviated status:
git diff --name-status
git diff --cached --name-status

create new branch:
git checkout -b branch_name
list branches:
git branch
switch branches
git checkout branch_name

temporarily go back to older state:
git checkout [commit_hash]
...do some stuff...
(can make a new branch here with:
git checkout -b branch_name
)
to switch back:
git checkout master [or whatever original_branch was]


Make a new copy on different computer:
git clone https://github.com/user/project

simple git guide here: http://rogerdudler.github.io/git-guide/

if you get error like:
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/user/project.git/info/refs
run:
git remote set-url origin https://user@github.com/user/project.git
(see http://stackoverflow.com/questions/7438313/pushing-to-git-returning-error-code-403-fatal-http-request-failed )

Sunday, February 15, 2015

Make Zotero export to bibtex handle latex math

The default bibtex export module for Zotero is not great at handling math in titles. The only good solution I have found is to change the manually change the titles from using Unicode symbols (γp→ϕp) to using latex math ($\gamma p \to \phi p$). Then you need to modify the bibtex export module so that it will output your math verbatim without escaping it. Modify the file [Firefox profile]/zotero/translators/BibTeX.js. Change
var alwaysMap = {
  "|":"{\\textbar}",
  "<":"{\\textless}",
  ">":"{\\textgreater}",
  "~":"{\\textasciitilde}",
  "^":"{\\textasciicircum}",
  "\\":"{\\textbackslash}",
  "{" : "\\{",
  "}" : "\\}"
};
to
var alwaysMap = {
  "|":"{\\textbar}",
  "<":"{\\textless}",
  ">":"{\\textgreater}",
  "~":"{\\textasciitilde}"//,
  //"^":"{\\textasciicircum}",
  //"\\":"{\\textbackslash}",
  //"{" : "\\{",
  //"}" : "\\}"
};
and in the function writeField() change
    value = value.replace(/[|\<\>\~\^\\\{\}]/g, mapEscape).replace(/([\#\$\%\&\_])/g, "\\$1");
to
    value = value.replace(/[|\<\>\~]/g, mapEscape).replace(/([\#\%\&])/g, "\\$1");
    //extra protect all math against capitalization
    value = value.replace(/(\$.*?\$)/g,"{$1}");
The last line is needed to protect math from being auto-capitalized or auto-uncapitalized with two pairs of brackets. Without this line it's only surrounded by one pair of brackets, which is not always enough. Before fixing this, I had a problem where BibTeX kept changing \Lambda to \lambda, uncapitalizing my greek letters in inappropriate places.

References:
https://ohadsc.wordpress.com/2012/06/20/zotero-exporting-unicode-and-latex-constructs-to-bibtex/
https://forums.zotero.org/discussion/5324/bibtex-and-greek-characters/