Sign inSign up

szcq/sharelatex

By szcq

•Updated 3 months ago

Sharelatex image with full texlive packages and chinese fonts.

Image
0

3.1K

szcq/sharelatex repository overview

⁠ShareLaTeX Deployment Guide

This repository provides customized ShareLaTeX / Overleaf images for self-hosted deployments.

The images are provided as multi-platform images with support for linux/amd64 and linux/arm64.


⁠Table of Contents


⁠Using This Image

⁠Install and Configure Overleaf

This guide uses the official Overleaf Toolkit⁠ for deployment.

⁠1. Clone the Overleaf Toolkit
git clone https://github.com/overleaf/toolkit.git ./overleaf-toolkit
⁠2. Enter the Toolkit Directory
cd ./overleaf-toolkit
⁠3. Initialize the Configuration
bin/init

This creates the following files under the config directory:

config/
├── overleaf.rc
├── variables.env
└── version
⁠4. Enter the Configuration Directory
cd config
⁠5. Edit overleaf.rc

Example configuration:

# ShareLaTeX container
OVERLEAF_IMAGE_NAME=szcq/sharelatex

# Persistent data directory
OVERLEAF_DATA_PATH=/mydata/docker/overleaf/overleaf

# Set to true only when using Overleaf Server Pro
SERVER_PRO=false

# Use 127.0.0.1 if external access is not required
OVERLEAF_LISTEN_IP=0.0.0.0

# Service port
OVERLEAF_PORT=10802

Adjust other options as required for your environment.

OVERLEAF_IMAGE_NAME=szcq/sharelatex tells the Toolkit to use the image from this repository instead of the default Overleaf image.

⁠6. Edit version

For example:

6.0.1

The value must match a tag available in this repository.

⁠7. Start the Docker Services

Return to the Toolkit root directory if necessary:

cd ..

Then start the services:

bin/up -d
⁠8. Create the Administrator Account

Open the following page in your browser:

http://localhost:<service-port>/launchpad

For example, when using:

OVERLEAF_PORT=10802

open:

http://localhost:10802/launchpad

Enter an email address and password to create the first administrator account.

The /launchpad page is the standard method recommended by Overleaf for creating the initial administrator account.


⁠Notes
⁠1. Using Chinese and Other CJK Fonts

For projects that use Chinese fonts, open the project menu and select:

Menu
  → Compiler
  → XeLaTeX

XeLaTeX is generally required when the project depends on system-installed fonts through packages such as:

fontspec
xeCJK

⁠2. Starting and Stopping Overleaf

Enter the Overleaf Toolkit directory:

cd ./overleaf-toolkit

Start the services:

bin/start

Stop the services:

bin/stop

The Toolkit provides wrapper scripts around Docker Compose for managing the local Overleaf deployment.


⁠3. Sibling Containers for Community Edition

If you are not using Overleaf Server Pro, set Sibling Containers to false in overleaf.rc:

# Sibling Containers
SIBLING_CONTAINERS_ENABLED=false
DOCKER_SOCKET_PATH=/var/run/docker.sock

⁠Installing Custom Fonts After Container Creation

Proprietary system fonts are not bundled into this image by default.

If you need additional fonts, such as fonts copied from your own Windows installation or other locally licensed font files, you can install them into an already running ShareLaTeX / Overleaf container.

⁠Font Installation Script Usage Guide

This repository provides the helper script at the end of the repository overview⁠:

install-sharelatex-fonts.sh

Save the script locally, make it executable, and run it with one of the supported input options described below.

The script supports three input methods:

  • A ZIP archive containing fonts
  • A local directory containing fonts
  • A single font file

The default container name is:

sharelatex

If your container uses a different name, specify it with:

-c <container-name>

For example, if your container is named:

overleaf-sharelatex

use:

-c overleaf-sharelatex
⁠1. Make the Script Executable
chmod +x ./install-sharelatex-fonts.sh
⁠2. Install Fonts from a ZIP Archive

Using the default container name:

./install-sharelatex-fonts.sh -z Fonts.zip

Using a custom container name:

./install-sharelatex-fonts.sh \
  -c overleaf-sharelatex \
  -z Fonts.zip

The option order is flexible, so this is also valid:

./install-sharelatex-fonts.sh \
  -z Fonts.zip \
  -c overleaf-sharelatex
⁠3. Install Fonts from a Directory

Using the default container name:

./install-sharelatex-fonts.sh -d Fonts

Using a custom container name:

./install-sharelatex-fonts.sh \
  -c overleaf-sharelatex \
  -d Fonts

Example directory structure:

Fonts/
├── simsun.ttc
├── simhei.ttf
├── simkai.ttf
└── custom-font.otf
⁠4. Install a Single Font File

Using the default container name:

./install-sharelatex-fonts.sh -f simsun.ttc

Using a custom container name:

./install-sharelatex-fonts.sh \
  -c overleaf-sharelatex \
  -f simhei.ttf
⁠5. What the Script Does

The script automatically:

  1. Checks that Docker is installed
  2. Checks that the target container is running
  3. Creates the font directory inside the container:
/usr/share/fonts/addfonts
  1. Copies the selected font source into the container
  2. Installs unzip automatically when a ZIP archive is used and unzip is not already available
  3. Extracts ZIP archives into the font directory
  4. Refreshes the Fontconfig cache with:
fc-cache -fv

After installation, the fonts become available to applications inside the running container.

⁠6. Verify Installed Fonts

List all fonts visible to Fontconfig:

docker exec sharelatex fc-list

For a custom container name:

docker exec overleaf-sharelatex fc-list

Search for a specific font:

docker exec sharelatex \
  fc-list | grep -i "SimSun"

Example for Microsoft YaHei:

docker exec sharelatex \
  fc-list | grep -i "Microsoft YaHei"
⁠7. Important Notes
  • The ShareLaTeX / Overleaf container must already be running before the script is executed.
  • If the script reports that the container cannot be found, check the actual container name with:
docker ps --format '{{.Names}}'
  • Fonts are installed into:
/usr/share/fonts/addfonts
  • After importing fonts, newly compiled documents can use them.
  • If a project still cannot detect Chinese fonts, first verify that the compiler is set to:
XeLaTeX
  • Fonts installed with this script are stored in the current container's writable layer. If the container is deleted and recreated, the fonts must be installed again.
  • Only use fonts for which you have the appropriate license or redistribution rights.

⁠Font Installation Script

Save the following script as:

install-sharelatex-fonts.sh
#!/usr/bin/env bash
set -euo pipefail

CONTAINER_NAME="sharelatex"
ZIP_FILE=""
FONT_DIR=""
FONT_FILE=""

TARGET_DIR="/usr/share/fonts/addfonts"
TMP_ZIP="/tmp/sharelatex-fonts.zip"

usage() {
    cat <<EOF
Usage:
  $0 -z Fonts.zip [-c sharelatex]
  $0 -d Fonts     [-c sharelatex]
  $0 -f simsun.ttc [-c sharelatex]

Options:
  -c  Container name. Default: sharelatex
  -z  Local ZIP archive containing fonts, e.g. Fonts.zip
  -d  Local directory containing fonts, e.g. Fonts
  -f  Local single font file, e.g. simsun.ttc / simhei.ttf / simkai.ttf
  -h  Show this help message

Examples:
  $0 -z Fonts.zip
  $0 -d Fonts
  $0 -f simsun.ttc

  $0 -c overleaf -z Fonts.zip
  $0 -z Fonts.zip -c overleaf
  $0 -f simhei.ttf -c overleaf
EOF
}

while getopts ":c:z:d:f:h" opt; do
    case "$opt" in
        c)
            CONTAINER_NAME="$OPTARG"
            ;;
        z)
            ZIP_FILE="$OPTARG"
            ;;
        d)
            FONT_DIR="$OPTARG"
            ;;
        f)
            FONT_FILE="$OPTARG"
            ;;
        h)
            usage
            exit 0
            ;;
        :)
            echo "Error: option -$OPTARG requires an argument"
            usage
            exit 1
            ;;
        \?)
            echo "Error: unknown option -$OPTARG"
            usage
            exit 1
            ;;
    esac
done

input_count=0
[ -n "$ZIP_FILE" ] && input_count=$((input_count + 1))
[ -n "$FONT_DIR" ] && input_count=$((input_count + 1))
[ -n "$FONT_FILE" ] && input_count=$((input_count + 1))

if [ "$input_count" -eq 0 ]; then
    echo "Error: exactly one of -z, -d, or -f must be specified"
    usage
    exit 1
fi

if [ "$input_count" -gt 1 ]; then
    echo "Error: -z, -d, and -f are mutually exclusive"
    usage
    exit 1
fi

if ! command -v docker >/dev/null 2>&1; then
    echo "Error: docker command not found"
    exit 1
fi

if ! docker ps --format '{{.Names}}' | grep -qx "$CONTAINER_NAME"; then
    echo "Error: container '$CONTAINER_NAME' is not running"
    echo "Currently running containers:"
    docker ps --format '  {{.Names}}'
    exit 1
fi

echo "Creating font directory in container: $TARGET_DIR"
docker exec -u root "$CONTAINER_NAME" mkdir -p "$TARGET_DIR"

if [ -n "$ZIP_FILE" ]; then
    if [ ! -f "$ZIP_FILE" ]; then
        echo "Error: ZIP file not found: $ZIP_FILE"
        exit 1
    fi

    echo "Copying ZIP archive into container: $ZIP_FILE"
    docker cp "$ZIP_FILE" "$CONTAINER_NAME:$TMP_ZIP"

    echo "Extracting fonts into: $TARGET_DIR"
    docker exec -u root "$CONTAINER_NAME" bash -lc "
set -e

if ! command -v unzip >/dev/null 2>&1; then
    apt-get update
    apt-get install -y --no-install-recommends unzip
    rm -rf /var/lib/apt/lists/*
fi

unzip -o '$TMP_ZIP' -d '$TARGET_DIR'
rm -f '$TMP_ZIP'
"
fi

if [ -n "$FONT_DIR" ]; then
    if [ ! -d "$FONT_DIR" ]; then
        echo "Error: font directory not found: $FONT_DIR"
        exit 1
    fi

    echo "Copying font directory contents into: $TARGET_DIR"
    docker cp "$FONT_DIR/." "$CONTAINER_NAME:$TARGET_DIR/"
fi

if [ -n "$FONT_FILE" ]; then
    if [ ! -f "$FONT_FILE" ]; then
        echo "Error: font file not found: $FONT_FILE"
        exit 1
    fi

    echo "Copying font file into: $TARGET_DIR"
    docker cp "$FONT_FILE" "$CONTAINER_NAME:$TARGET_DIR/"
fi

echo "Refreshing font cache..."
docker exec -u root "$CONTAINER_NAME" fc-cache -fv

echo "Done. Fonts have been installed into: $TARGET_DIR"

Tag summary

Content type

Image

Digest

sha256:86838101c…

Size

3.6 GB

Last updated

3 months ago

docker pull szcq/sharelatex:6.2.0