diff --git a/latex-env-for-papers/latex-docker/Dockerfile b/latex-env-for-papers/latex-docker/Dockerfile new file mode 100644 index 0000000..e249558 --- /dev/null +++ b/latex-env-for-papers/latex-docker/Dockerfile @@ -0,0 +1,54 @@ +FROM ubuntu:22.04 + +ARG DEBIAN_FRONTEND=noninteractive + +# ── System dependencies ──────────────────────────────────────────────────────── +RUN apt-get update && apt-get install -y --no-install-recommends \ + apt-transport-https \ + ca-certificates \ + curl \ + dirmngr \ + gnupg \ + lsb-release \ + perl \ + python3 \ + wget \ + git \ + make \ + fonts-liberation \ + && rm -rf /var/lib/apt/lists/* + +# ── MiKTeX ───────────────────────────────────────────────────────────────────── +RUN curl -fsSL https://miktex.org/download/key | gpg --dearmor -o /usr/share/keyrings/miktex-keyring.gpg \ + && echo "deb [arch=amd64 signed-by=/usr/share/keyrings/miktex-keyring.gpg] https://miktex.org/download/ubuntu jammy universe" \ + > /etc/apt/sources.list.d/miktex.list \ + && apt-get update \ + && apt-get install -y --no-install-recommends miktex \ + && rm -rf /var/lib/apt/lists/* + +# Finish MiKTeX setup & enable auto-install of missing packages +RUN miktexsetup --shared=yes finish \ + && initexmf --admin --set-config-value "[MPM]AutoInstall=1" \ + && mpm --admin --update-db + +# ── code-server (browser VS Code) ───────────────────────────────────────────── +RUN curl -fsSL https://code-server.dev/install.sh | sh + +# ── LaTeX Workshop extension ─────────────────────────────────────────────────── +RUN code-server --install-extension James-Yu.latex-workshop --force + +# ── Workspace ───────────────────────────────────────────────────────────────── +RUN mkdir -p /workspace +WORKDIR /workspace + +# ── code-server config ───────────────────────────────────────────────────────── +RUN mkdir -p /root/.config/code-server +COPY config.yaml /root/.config/code-server/config.yaml + +# ── LaTeX Workshop settings ──────────────────────────────────────────────────── +RUN mkdir -p /root/.local/share/code-server/User +COPY settings.json /root/.local/share/code-server/User/settings.json + +EXPOSE 8080 + +CMD ["code-server", "--bind-addr", "0.0.0.0:8080", "/workspace"] \ No newline at end of file diff --git a/latex-env-for-papers/latex-docker/README.md b/latex-env-for-papers/latex-docker/README.md new file mode 100644 index 0000000..146aa13 --- /dev/null +++ b/latex-env-for-papers/latex-docker/README.md @@ -0,0 +1,69 @@ +# LaTeX Dev Environment — MiKTeX + code-server + +A self-contained LaTeX environment that runs in Docker and is accessible via your browser. + +## Stack +| Component | Details | +|---|---| +| LaTeX distro | MiKTeX (auto-installs missing packages) | +| Editor | code-server (VS Code in the browser) | +| Extension | LaTeX Workshop (auto-build on save, PDF preview) | + +--- + +## Quick Start + +```bash +# 1. Build & start +docker compose up --build + +# 2. Open your browser +open http://localhost:8080 + +# 3. Open workspace/main.tex and start writing! +``` + +The first build takes a few minutes (MiKTeX is ~500 MB). +Subsequent starts are fast thanks to the `miktex-cache` volume. + +--- + +## Usage + +- **Auto-build**: saves trigger a compile automatically. +- **Manual build**: `Ctrl+Alt+B` (or click the green ▶ in the LaTeX Workshop sidebar). +- **PDF preview**: opens in a side tab — use `Ctrl+Alt+V`. +- **Change compiler**: open the LaTeX Workshop sidebar → pick a recipe (pdfLaTeX, XeLaTeX, LuaLaTeX, etc.). +- **Your files**: put everything inside `./workspace/` — it's bind-mounted into the container. + +--- + +## Stopping & Restarting + +```bash +docker compose down # stop (workspace files are safe) +docker compose up # restart (no rebuild needed) +docker compose up --build # rebuild image (after Dockerfile changes) +``` + +--- + +## Adding Packages Manually + +MiKTeX auto-installs packages on first compile. To install manually: + +```bash +docker exec -it latex-dev mpm --install +``` + +--- + +## Security Note + +`config.yaml` sets `auth: none` — fine for local use. If you expose port 8080 +publicly, set a password: + +```yaml +auth: password +password: your-strong-password +``` \ No newline at end of file diff --git a/latex-env-for-papers/latex-docker/config.yaml b/latex-env-for-papers/latex-docker/config.yaml new file mode 100644 index 0000000..0539363 --- /dev/null +++ b/latex-env-for-papers/latex-docker/config.yaml @@ -0,0 +1,3 @@ +bind-addr: 0.0.0.0:8080 +auth: none +cert: false \ No newline at end of file diff --git a/latex-env-for-papers/latex-docker/docker-compose.yaml b/latex-env-for-papers/latex-docker/docker-compose.yaml new file mode 100644 index 0000000..f774253 --- /dev/null +++ b/latex-env-for-papers/latex-docker/docker-compose.yaml @@ -0,0 +1,15 @@ +services: + latex: + build: . + container_name: latex-dev + ports: + - "8080:8080" + volumes: + # Your local projects folder → /workspace inside the container + - ./workspace:/workspace + # Persist MiKTeX package cache between restarts + - miktex-cache:/var/cache/miktex + restart: unless-stopped + +volumes: + miktex-cache: \ No newline at end of file diff --git a/latex-env-for-papers/latex-docker/settings.json b/latex-env-for-papers/latex-docker/settings.json new file mode 100644 index 0000000..bc33f26 --- /dev/null +++ b/latex-env-for-papers/latex-docker/settings.json @@ -0,0 +1,77 @@ +{ + "latex-workshop.latex.tools": [ + { + "name": "pdflatex", + "command": "pdflatex", + "args": [ + "-synctex=1", + "-interaction=nonstopmode", + "-file-line-error", + "%DOC%" + ] + }, + { + "name": "xelatex", + "command": "xelatex", + "args": [ + "-synctex=1", + "-interaction=nonstopmode", + "-file-line-error", + "%DOC%" + ] + }, + { + "name": "lualatex", + "command": "lualatex", + "args": [ + "--synctex=1", + "--interaction=nonstopmode", + "--file-line-error", + "%DOC%" + ] + }, + { + "name": "biber", + "command": "biber", + "args": ["%DOCFILE%"] + }, + { + "name": "bibtex", + "command": "bibtex", + "args": ["%DOCFILE%"] + } + ], + "latex-workshop.latex.recipes": [ + { + "name": "pdfLaTeX", + "tools": ["pdflatex"] + }, + { + "name": "pdfLaTeX × 2", + "tools": ["pdflatex", "pdflatex"] + }, + { + "name": "pdfLaTeX + Biber", + "tools": ["pdflatex", "biber", "pdflatex", "pdflatex"] + }, + { + "name": "XeLaTeX", + "tools": ["xelatex"] + }, + { + "name": "LuaLaTeX", + "tools": ["lualatex"] + } + ], + "latex-workshop.latex.autoBuild.run": "onSave", + "latex-workshop.view.pdf.viewer": "tab", + "latex-workshop.latex.clean.fileTypes": [ + "*.aux", "*.bbl", "*.blg", "*.idx", "*.ind", + "*.lof", "*.lot", "*.out", "*.toc", "*.acn", + "*.acr", "*.alg", "*.glg", "*.glo", "*.gls", + "*.ist", "*.fls", "*.log", "*.fdb_latexmk", "*.synctex.gz" + ], + "editor.formatOnSave": false, + "files.autoSave": "afterDelay", + "files.autoSaveDelay": 1000 +} \ No newline at end of file diff --git a/latex-env-for-papers/latex-docker/workspace/main.tex b/latex-env-for-papers/latex-docker/workspace/main.tex new file mode 100644 index 0000000..3da0f31 --- /dev/null +++ b/latex-env-for-papers/latex-docker/workspace/main.tex @@ -0,0 +1,38 @@ +\documentclass[12pt, a4paper]{article} + +\usepackage{amsmath} +\usepackage{amssymb} +\usepackage{hyperref} +\usepackage{geometry} +\geometry{margin=2.5cm} + +\title{My First Document} +\author{Your Name} +\date{\today} + +\begin{document} + +\maketitle + +\section{Introduction} +Welcome to your Dockerised \LaTeX{} environment powered by MiKTeX and VS Code. + +\section{Math Example} +Einstein's famous equation: +\begin{equation} + E = mc^2 +\end{equation} + +The quadratic formula: +\begin{equation} + x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} +\end{equation} + +\section{Lists} +\begin{itemize} + \item MiKTeX auto-installs missing packages on first compile. + \item Save any \texttt{.tex} file to trigger an automatic build. + \item The PDF viewer opens in a side tab inside VS Code. +\end{itemize} + +\end{document} \ No newline at end of file