huangyxi / how-to-use-latex-in-termux

How to Use LaTeX in Termux with Custom Fonts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use LaTeX in Termux with custom fonts

  1. Install TeX Live and dependences
# install texlive
apt install texlive

# install fontconfig-utils which includes `fc-list`
apt install fontconfig-utils

# change the remote repository to the mirror close to you 
tlmgr option repository https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/tlnet

# update tlmgr
tlmgr update --all
  1. Install custom fonts
# make a new directory to store your custom fonts
CUSTOM_FONT_PATH="/data/data/com.termux/files/usr/share/fonts/YOUR_DIR_NAME"
mkdir -p "${CUSTOM_FONT_PATH}"

# copy fonts from somewhere else to the path of your custom fonts
cp [YOUR_FONTS_PATH/*] "${CUSTOM_FONT_PATH}"
chmod 744 "${CUSTOM_FONT_PATH}"/*
fc-cache -f -v

# better to export the path in ~/.bashrc
export OSFONTDIR="/data/data/com.termux/files/usr/share/fonts"

# add the font Fandol
tlmgr install fandol
  1. Install LaTeX packages
# reinstall  l3packages
tlmgr install --reinstall --with-doc --with-src l3packages

# install ctex to parse Chinese if you need
tlmgr install --with-doc --with-src ctex
  1. Write a LaTeX demo in file demo.tex
# goto a temporary directory
cd $(mktemp -d); pwd

DEMO_FILE=$demo.tex$
echo "\document{article}" > "${DEMO_FILE}"

# "font=windows" if you copied Chinese fonts from Windows
echo "\usepackage[fontset=windows]{ctex}" >> "${DEMO_FILE}"

echo "\begin{document}" >> "${DEMO_FILE}"

echo 'Hello $\LaTeX$' >> "${DEMO_FILE}"
echo "测试" >> "${DEMO_FILE}" # or in other languages 

echo "\end{document}" >> "${DEMO_FILE}"
  1. compile the LaTeX file demo.tex
xelatex -synctex=1 -interaction=nonstopmode demo.tex

# install lost packages if needed
tlmgr install --with-doc --with-src LOST_PACKAGE

xelatex -synctex=1 -interaction=nonstopmode demo.tex
tlmgr install --with-doc --with-src LOST_PACKAGE

xelatex -synctex=1 -interaction=nonstopmode demo.tex
tlmgr install --with-doc --with-src LOST_PACKAGE
# ...
  1. Open the PDF file by your Android PDF reader
termux-open demo.pdf

About

How to Use LaTeX in Termux with Custom Fonts

License:Apache License 2.0