init commit

This commit is contained in:
2025-09-08 23:18:15 +05:30
parent 182bdc2b5a
commit 38a464e907
5 changed files with 293 additions and 0 deletions

23
Dockerfile Normal file
View File

@@ -0,0 +1,23 @@
FROM alpine:3.22
# update and install latex packages
RUN echo test
RUN apk update
RUN apk add entr texlive-full
# creating container structure
ENV mainFile=""
RUN addgroup -g 1000 -S ltxgroup && adduser -u 1000 -S -G ltxgroup ltxuser
RUN mkdir -p /app && chown -R ltxuser:ltxgroup /app
WORKDIR /app
# copy install scripts
USER ltxuser
COPY --chown=ltxuser:ltxgroup startup.sh /app/startup.sh
RUN chmod +x /app/startup.sh
RUN echo arstearst
COPY --chown=ltxuser:ltxgroup setupFiles /app/setupFiles
RUN chmod +x /app/setupFiles/install.sh
CMD [ "sh", "-c", "/app/startup.sh ${mainFile}" ]
# CMD [ "ls", "|", "entr", "ls", "-hla" ]

29
setupFiles/compile.sh Normal file
View File

@@ -0,0 +1,29 @@
#! /bin/bash
# Adapted from github.com/gkilleen33/overleaf-offline under the MIT license
mkdir -p pdf
if test -f "pdf/output.aux"; then
rm pdf/*
fi
latexmk -C
latexmk -pdf -jobname=pdf/output main.tex -f
count=`ls -1 *.aux 2>/dev/null | wc -l`
if [ $count != 0 ]
then
mv *.aux pdf/
fi
count=`ls -1 *.bbl 2>/dev/null | wc -l`
if [ $count != 0 ]
then
mv *.bbl pdf/
fi
count=`ls -1 *.blg 2>/dev/null | wc -l`
if [ $count != 0 ]
then
mv *.blg pdf/
fi
mkdir -p pdf/log
find pdf -maxdepth 1 -type f -not -name 'output.pdf' -exec mv {} pdf/log/ \;
mv pdf/output.pdf .

32
setupFiles/install.sh Normal file
View File

@@ -0,0 +1,32 @@
#! /bin/bash
# Adapted from github.com/gkilleen33/overleaf-offline under the MIT license
# Add build files to gitignore
cd /app/project
if test -f ".autoltx"; then
echo AutoLTX already installed, skipping steup
else
if test -f ".gitignore"; then
# Adding build files to .gitignore
grep -qxF 'build/' .gitignore || echo 'build/' >> .gitignore
grep -qxF 'latexmkrc' .gitignore || echo 'latexmkrc' >> .gitignore
grep -qxF 'compile.sh' .gitignore || echo 'compile.sh' >> .gitignore
grep -qxF '.autoltx' .gitignore || echo '.autoltx' >> .gitignore
touch .autoltx
echo Configuring AutoLTX for this project
else
# Creating .gitignore file
printf 'build/\nlatexmkrc\ncompile.sh\n' >> .gitignore
fi
# mkdir -p build/config
# Add latexmk rc file to build files
cp /app/setupFiles/latexmkrc /app/project/
# Add compile script to build files
cp /app/setupFiles/compile.sh /app/project
chmod +x compile.sh
fi

180
setupFiles/latexmkrc Normal file
View File

@@ -0,0 +1,180 @@
# Adapted from github.com/gkilleen33/overleaf-offline under the MIT license
###############################
# Post processing of pdf file #
###############################
# assume the jobname is 'output' for Overleaf v2
my $ORIG_PDF_AGE = -M "output.pdf"; # get age of existing pdf if present
END {
my $NEW_PDF_AGE = -M "output.pdf";
return if !defined($NEW_PDF_AGE); # bail out if no pdf file
return if defined($ORIG_PDF_AGE) && $NEW_PDF_AGE == $ORIG_PDF_AGE; # bail out if pdf was not updated
my $QPDF = "/usr/bin/qpdf";
return if ! -x $QPDF; # check that qpdf exists
my $status = system($QPDF, "--linearize", "output.pdf", "output.pdf.opt");
my $exitcode = ($status >> 8);
print "qpdf exit code=$exitcode\n";
# qpdf returns 0 for success, 3 for warnings (output pdf still created)
return if !($exitcode == 0 || $exitcode == 3);
print "Renaming optimised file to output.pdf\n";
rename("output.pdf.opt", "output.pdf");
}
##############
# Glossaries #
##############
add_cus_dep( 'glo', 'gls', 0, 'glo2gls' );
add_cus_dep( 'acn', 'acr', 0, 'glo2gls'); # from Overleaf v1
sub glo2gls {
system("makeglossaries $_[0]");
}
#############
# makeindex #
#############
@ist = glob("*.ist");
if (scalar(@ist) > 0) {
$makeindex = "makeindex -s $ist[0] %O -o %D %S";
}
################
# nomenclature #
################
add_cus_dep("nlo", "nls", 0, "nlo2nls");
sub nlo2nls {
system("makeindex $_[0].nlo -s nomencl.ist -o $_[0].nls -t $_[0].nlg");
}
#########
# Knitr #
#########
my $root_file = $ARGV[-1];
add_cus_dep( 'Rtex', 'tex', 0, 'rtex_to_tex');
sub rtex_to_tex {
do_knitr("$_[0].Rtex");
}
sub do_knitr {
my $dirname = dirname $_[0];
my $basename = basename $_[0];
system("Rscript -e \"library('knitr'); setwd('$dirname'); knit('$basename')\"");
}
my $rtex_file = $root_file =~ s/\.tex$/.Rtex/r;
unless (-e $root_file) {
if (-e $rtex_file) {
do_knitr($rtex_file);
}
}
##########
# feynmf #
##########
push(@file_not_found, '^feynmf: Files .* and (.*) not found:$');
add_cus_dep("mf", "tfm", 0, "mf_to_tfm");
sub mf_to_tfm { system("mf '\\mode:=laserjet; input $_[0]'"); }
push(@file_not_found, '^feynmf: Label file (.*) not found:$');
add_cus_dep("mf", "t1", 0, "mf_to_label1");
sub mf_to_label1 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t1"); }
add_cus_dep("mf", "t2", 0, "mf_to_label2");
sub mf_to_label2 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t2"); }
add_cus_dep("mf", "t3", 0, "mf_to_label3");
sub mf_to_label3 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t3"); }
add_cus_dep("mf", "t4", 0, "mf_to_label4");
sub mf_to_label4 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t4"); }
add_cus_dep("mf", "t5", 0, "mf_to_label5");
sub mf_to_label5 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t5"); }
add_cus_dep("mf", "t6", 0, "mf_to_label6");
sub mf_to_label6 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t6"); }
add_cus_dep("mf", "t7", 0, "mf_to_label7");
sub mf_to_label7 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t7"); }
add_cus_dep("mf", "t8", 0, "mf_to_label8");
sub mf_to_label8 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t8"); }
add_cus_dep("mf", "t9", 0, "mf_to_label9");
sub mf_to_label9 { system("mf '\\mode:=laserjet; input $_[0]' && touch $_[0].t9"); }
##########
# feynmp #
##########
push(@file_not_found, '^dvipdf: Could not find figure file (.*); continuing.$');
add_cus_dep("mp", "1", 0, "mp_to_eps");
sub mp_to_eps {
system("mpost $_[0]");
return 0;
}
#############
# asymptote #
#############
sub asy {return system("asy --offscreen '$_[0]'");}
add_cus_dep("asy","eps",0,"asy");
add_cus_dep("asy","pdf",0,"asy");
add_cus_dep("asy","tex",0,"asy");
#############
# metapost # # from Overleaf v1
#############
add_cus_dep('mp', '1', 0, 'mpost');
sub mpost {
my $file = $_[0];
my ($name, $path) = fileparse($file);
pushd($path);
my $return = system "mpost $name";
popd();
return $return;
}
##########
# chktex #
##########
unlink 'output.chktex' if -f 'output.chktex';
if (defined $ENV{'CHKTEX_OPTIONS'}) {
use File::Basename;
use Cwd;
# identify the main file
my $target = $ARGV[-1];
my $file = basename($target);
if ($file =~ /\.tex$/) {
# change directory for a limited scope
my $orig_dir = cwd();
my $subdir = dirname($target);
chdir($subdir);
# run chktex on main file
$status = system(
"/usr/bin/run-chktex.sh",
$orig_dir,
$file
);
# go back to original directory
chdir($orig_dir);
# in VALIDATE mode we always exit after running chktex
# otherwise we exit if EXIT_ON_ERROR is set
if ($ENV{'CHKTEX_EXIT_ON_ERROR'} || $ENV{'CHKTEX_VALIDATE'}) {
# chktex doesn't let us access the error info via exit status
# so look through the output
open(my $fh, "<", "output.chktex");
my $errors = 0;
{
local $/ = "\n";
while(<$fh>) {
if (/^\S+:\d+:\d+: Error:/) {
$errors++;
print;
}
}
}
close($fh);
exit(1) if $errors > 0;
exit(0) if $ENV{'CHKTEX_VALIDATE'};
}
}
}

29
startup.sh Normal file
View File

@@ -0,0 +1,29 @@
#! /bin/bash
echo Running as user: $USER
if [[ -z ${1} ]]; then
echo Main file not spicified
echo Restart the container with proper arguments
exit 1
else
echo Using main latex file: $1
fi
if test -d /app/project; then
echo Files in current project:
ls -hl /app/project
else
echo Project folder not mounted
echo Restart the container with proper project mount
exit 1
fi
# install autoltx to project
/app/setupFiles/install.sh
# start auto compile loop
echo Starting AutoLTX...
sleep 3
cd /app/project
ls $1 | entr -n sh -c ./compile.sh