A simple setup guide to get a working environment for compiling and editing LaTeX documents on Android using Tectonic (Compiler), Neovim (Editor) with plugins for code completion and compilation in Termux. This can work on any other Linux distro with their respective package manager.
All further steps to be followed in Termux.
pkg up
termux-setup-storage
pkg install neovim nodejs python clang fd ripgrep lua51 luarocks lua-language-server stylua texlab
If anything is missing it'll just pop up once you run :LazyHealth
later, then install it.
pkg install tectonic
Tectonic is a user focused LaTeX compiler, it's mentioned here, since no almost no setup required for running it, and works best. (I sadly did not get any sponsorship for this 🥲)
For further finer details please visit the project : tectonic
Now there are two options:
- Using the zip file provided with this gist
- And for the untrustworthy (like me) : Complete Manual Setup
Tbh I suggest using this method as all you have to do is :
mkdir -p ~/.config/nvim/
cd ~/.config/nvim/
mv <path/to/zip> ~/.config/nvim/
unzip zip_file
nvim
And Voila !!! you've done it. Get on with Compiling your tex
files.
Check Usage
.
I wouldn't suggest downloading any zip file off of the internet and push it to my .config directory (I wouldn't do it myself), but here I assure you there isn't any malicious code in it. There's also another option before executing neovim read-through all the files.
And for the unconvinced :
mv ~/.config/nvim{,.bak}
git clone https://github.com/LazyVim/starter ~/.config/nvim
For more details read-up : LazyVim
cd ~/.config/nvim/lua/plugins/
nvim vimtex.lua
Add the following snippet to vimtex.lua
return {
"lervag/vimtex",
-- init = function()
-- Vimtex configurations
--vim.g.vimtex_view_general_viewer = "zathura"
-- end,
}
Add the following to
~/.config/nvim/init.lua
require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/lua/snippets/" })
vim.g.vimtex_compiler_method = "tectonic"
vim.g.vimtex_view_general_viewer = "termux-open"
Enable LuaSnip in LazyExtras from the dashboard.
To enable press 'x' on dashboard, press '/' this opens search, search for 'luasnip', press enter, by pressing n reach coding.luasnip
, press 'x' to enable it.
Adding snippets:
mkdit -p ~/.config/nvim/lua/snippets/
touch tex.lua
Add the following snippet to tex.lua
local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
--local rep = require("luasnip.extras").rep
local fmta = require("luasnip.extras.fmt").fmta
ls.add_snippets("tex", {
s({ trig = "hw" }, { t("Hello, World !!!") }),
s(
{ trig = "article" },
fmta(
[[
\documentclass[12pt]{article}
\title{<>}
\author{<>}
\date{}
\begin{document}
\maketitle
<>
\end{document}
]],
{ i(1), i(2), i(3) }
)
),
})
And Done.
I'd suggest making a directory for writing articles, to keep it tidy.
cd ~
mkdir -p articles
cd articles
mkdir article_1
cd article_1
nvim test.tex
In Neovim type article
a pop-up will be shown. Press enter and snippet will be inserted, use <tab>
to navigate jump points.
For compilation read-up :- Vimtex
TLDR:
<ESC>
to enter NORMAL mode,
\ll
to compile,
\lv
to view pdf,
And the age-old joke, to exit Neo/vim :
:wq
save & quit,
:q!
quit without saving changes,
:q
quit
Workaround for Mason installing error lua_ls
:
ln -f -s "$(command -v lua-language-server)" /data/data/com.termux/files/home/.local/share/nvim/mason/packages/lua-language-server/libexec/bin/lua-language-server
Get pretty colors & fonts in Termux:
git clone https://github.com/adi1090x/termux-style
cd termux-style
./install.sh
termux-style
Choose whatever you like. I personally recommend using Tokyonight, also install Tokyonight colorscheme for Neovim. Thankyou for reading, Any suggestions and constructive criticism is welcomed, DM on Reddit
1000062673.mp4
Demo video.