Latex rendering in README.md on Github

前端 未结 12 1026
挽巷
挽巷 2020-12-22 16:59

Is there any way to render LaTex in README.md in a GitHub repository? I\'ve googled it and searched on stack overflow but none of the related answers seems feasible.

12条回答
  •  抹茶落季
    2020-12-22 17:46

    You can get a continuous integration service (e.g. Travis CI) to render LaTeX and commit results to github. CI will deploy a "cloud" worker after each new commit. The worker compiles your document into pdf and either cuses ImageMagick to convert it to an image or uses PanDoc to attempt LaTeX->HTML conversion where success may vary depending on your document. Worker then commits image or html to your repository from where it can be shown in your readme.

    Sample TravisCi config that builds a PDF, converts it to a PNG and commits it to a static location in your repo is pasted below. You would need to add a line that fetches pdfconverts PDF to an image

    sudo: required
    dist: trusty
    os: linux
    language: generic
    services: docker
    env:
      global:
      - GIT_NAME: Travis CI
      - GIT_EMAIL: builds@travis-ci.org
      - TRAVIS_REPO_SLUG: your-github-username/your-repo
      - GIT_BRANCH: master
    # I recommend storing your GitHub Access token as a secret key in a Travis CI environment variable, for example $GH_TOKEN.
      - secure: ${GH_TOKEN}
    script:
    - wget https://raw.githubusercontent.com/blang/latex-docker/master/latexdockercmd.sh
    - chmod +x latexdockercmd.sh
    - "./latexdockercmd.sh latexmk -cd -f -interaction=batchmode -pdf yourdocument.tex -outdir=$TRAVIS_BUILD_DIR/"
    - cd $TRAVIS_BUILD_DIR
    - convert -density 300 -quality 90 yourdocument.pdf yourdocument.png
    - git checkout --orphan $TRAVIS_BRANCH-pdf
    - git rm -rf .
    - git add -f yourdoc*.png
    - git -c user.name='travis' -c user.email='travis' commit -m "updated PDF"
    # note we are again using GitHub access key stored in the CI environment variable
    - git push -q -f https://your-github-username:$GH_TOKEN@github.com/$TRAVIS_REPO_SLUG $TRAVIS_BRANCH-pdf
    notifications:
      email: false
    

    This Travis Ci configuration launches a Ubuntu worker downloads a latex docker image, compiles your document to pdf and commits it to a branch called branchanme-pdf.

    For more examples see this github repo and its accompanying sx discussion, PanDoc example, https://dfm.io/posts/travis-latex/, and this post on Medium.

提交回复
热议问题