diff --git a/src/slider/latexutils.py b/src/slider/latexutils.py
index bfc89c99919cfaf9b0783ebff5c40bc5f0874bdf..c41121a7e9814811136a3b26bbe312a1a778e0ed 100644
--- a/src/slider/latexutils.py
+++ b/src/slider/latexutils.py
@@ -5,7 +5,7 @@ import subprocess
 import glob
 import asyncio
 
-def latexmk(texfile,pdf_out=None,shell=True,cleanup=False, Linux=False):
+def latexmk(texfile,pdf_out=None,shell=True,cleanup=False, Linux=False, compress_pdf=False):
     cdir = os.getcwd()
     texfile = os.path.abspath(texfile)
     dname = os.path.dirname(texfile)
@@ -37,19 +37,19 @@ def latexmk(texfile,pdf_out=None,shell=True,cleanup=False, Linux=False):
             fl = glob.glob(dname + "/*."+ex)
             for f in fl:
                 os.remove(f)
-
+    if compress_pdf:
+        cmd = f"""gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -e -o _{pdf_out} {pdf_out}"""
+        # cmds = [ f"""gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -e -o""", f"{dname}/{pdf_out}", f"{dname}/{pdf_out}"]
+        print("Compressing PDF file using command", cmd)
+        subprocess.run(cmd, shell=True)
+        shutil.move(f"_{pdf_out}", pdf_out)
+        print("[done]")
     os.chdir(cdir)
     return pdf_out
 
 async def latexmk_async(texfile, pdf_out=None, cleanup=False):
     cdir = os.getcwd()
     texfile = os.path.abspath(texfile)
-    import tempfile
-    # with tempfile.TemporaryDirectory() as tmp:
-    # print('created temporary directory', tmpdirname)
-    # shutil.rmtree(tmp)
-    # shutil.copytree(os.path.dirname(texfile), tmp)
-    # tmp_texfile = tmp + "/" + os.path.basename(texfile)
     tmp_texfile = texfile
     compiled_pdf = tmp_texfile[:-4] + ".pdf"
     if os.path.isfile(compiled_pdf):