Blog 1

Random Talk on Random Thoughts

$\rm \LaTeX$-Suite in Portable Git

| Comments |

Background

A year ago, I was using msysgit on M$ Win* 7. Its support for Unicode characters isn’t so good, and I can’t write a text file with accents like “café” in the Vim editor that shipped with msysgit. As a result, I needed GVim for editing my $\rm \LaTeX$ documents.

Unluckily, unlike Linux, the GVim can never have forward control. Therefore, I needed to switch windows between GVim and Git Bash.

More importantly, if I want to apply the Linux skills and the tools on M$ Win*, I need portable programs excutable on a USB unless I carry my laptop.

Luckily, the bash shell in Git for Windows has improved a lot. The accents are well supported. Then, I have switched from GVim to the embedded Vim in Git for Windows. Luckily, the setup of Vundle was smooth. Most of the installed plugins work fine in terminal Vim.

Problem 1

In the post Git Portable Home Path, a BAT file is included so that the home folder and the HOMEDRIVE environment are automatically set. Since the same Git repository can be shared among multiple devices, such as my Linux desktop, my M$ Win* 7 laptop, and my USB stick, a bare repository is needed for efficient pulling and pushing of Git commits. Since I work outside home, I place a bare Git repo in my USB stick. However, for each local Git repository stored in the USB stick (under ~/local_repo, a.k.a. $HOMEDRIVE/PortableGit/home/owner/local_repo), I need to run the following command for each time I use Git Bash.

Problem 2

After making some changes on a $\rm \TeX$ file, I compiled the file using Mik$\rm \TeX$ Portable.

  1. Browse the folder $HOMEDRIVE/MikTeXPortable/.
  2. Double-click on miktex-portable.cmd.
  3. In the Command Prompt popped up, switch to $HOMEDRIVE/PortableGit/home/owner/local_repo.
  4. Type pdflatex file.tex.

This sounds really slow. The goal is to find a more efficient $\rm \LaTeX$ editing workflow.

That’s not the end. Another bad news came from eu1lmr.fd. I’ve got error similar to fengbaobao6’s. The compilation was stuck at ...\tex\latex\euenc\eu1lmr.fd. Then an error was shown: “Fontconfig error: Cannot load config file”.

Solution 1

  1. Create a file ~/.bashrc if it doesn’t exist.
  2. Write an array consisting of all local Git repositories saved in the USB stick in BASHRC.
  3. Then Write a for loop to reset the remote location.

Solution 2

Searching the error text, I found kounoupis’s answer on Ask Ubuntu. Even though the export command didn’t work for me, I still found his answer informative.

Finally, reading miktex-portable.cmd, I gave up on investigating the problem, and added the last line of this file into BASHRC since I have other important things to do.

Actual CMD file found in Mik$\rm \TeX$ Portable (miktex-portable.cmd) download
1
2
3
@echo off
cd /d %~dp0
miktex\bin\miktex-taskbar-icon.exe

To include Mik$\rm \TeX$ into PATH, I first extracted $HOMEDRIVE in the form /f instead of F:/. If not, Mik$\rm \TeX$ won’t work.

Conclusion

Here’s my BASHRC for Git Bash.

My BASHRC (bashrc) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
stty -ixon
cd ~

HOMEDRIVE=$(perl -e '($var) = $ENV{HOMEDRIVE} =~ /([A-Z]):/; print "/".lc($1)')
if [ $(perl -e '($var) = $ENV{PATH} !~ /tex/i; print STDOUT $var') ]
then
    echo "No LaTeX found!  Added $HOMEDRIVE/MikTeXPortable/miktex/bin
    to path."
    PATH=$PATH:$HOMEDRIVE/MikTeXPortable/miktex/bin
    echo "IMPORTANT: Close MikTeX Taskbar icon before exit."
    echo "Otherwise this shell WON'T close."
    miktex-taskbar-icon
fi

loc_repo=(
'resume2015'
)

for f in ${loc_repo[@]}; do
    cd $f
    git remote set-url origin $HOMEDRIVE/$f.git
    cd -
done

If the setup is correct, then \ll in $\rm \LaTeX$-Suite should automatically trigger the $\rm \LaTeX$ compilation. I give up on finding ways to open a viewer with \lv since I can use the keyboard to switch to a web browser to see the compiled PDF file without installing another PDF viewer in my USB stick.

Lessons learnt

I’ve learnt some Perl and bash after writing this BASHRC.

  1. A little bit of Perl
    • $ENV{HOMEDRIVE} for extracting the environment variable HOMEDRIVE.
    • /(regex_pat)/; for extracting matching string to capture groups $1, $2… (The () around regex_pat is crucial.)
    • . for string concatenation.
    • lc() for converting a string to lowercase.
  2. Bash for loop writing: described in one of my recent posts.

Comments