Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
eliselavy authored Sep 11, 2024
1 parent 42a47f4 commit 6f699d1
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions convert-notebook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# to use it: ./convert-notebook.sh <pid_of_the_article>
#!/bin/bash

# Check if a parameter is provided
if [ -z "$1" ]; then
echo "Usage: $0 <pid_of_the_article>"
exit 1
fi

# Assign the parameter to a variable
PID=$1

# FIRST STEP: Get the ipynb from the server
echo "Fetching notebook from server..."
scp [email protected]:/opt/journal-digital-history-docker-stack/data/outputs/${PID}.ipynb .

# Check if the scp command was successful
if [ $? -ne 0 ]; then
echo "Failed to fetch notebook from server."
exit 1
fi

# SECOND STEP: Transform in latex
echo "Converting notebook to LaTeX..."
jupyter nbconvert --to latex ${PID}.ipynb

# Check if the nbconvert command was successful
if [ $? -ne 0 ]; then
echo "Failed to convert notebook to LaTeX."
exit 1
fi

# THIRD STEP: include images in the latex file
echo "Adjusting image inclusion in LaTeX file..."
sed -i '' 's/\\adjustimage{max size={0.9\\linewidth}{0.9\\paperheight}}{\([^}]*\)}/\\includegraphics[width=0.9\\linewidth, height=0.9\\paperheight, keepaspectratio]{\1}/g' ${PID}.tex

# Check if the sed command was successful
if [ $? -ne 0 ]; then
echo "Failed to adjust image inclusion in LaTeX file."
exit 1
fi

# FOR STEP: Transform in docx
echo "Converting LaTeX to DOCX..."
pandoc ${PID}.tex -s -o ${PID}.docx --resource-path=.

# Check if the pandoc command was successful
if [ $? -ne 0 ]; then
echo "Failed to convert LaTeX to DOCX."
exit 1
fi

echo "Conversion completed successfully."

0 comments on commit 6f699d1

Please sign in to comment.