ROUGH DRAFT authorea.com/7200
Main Data History
Export
Show Index Toggle 26 comments
  •  Quick Edit
  • How To Insert Code Blocks (Snippets)

    Authorea Help

    This is a simple example showing how to display code blocks and snippets in Authorea. Syntax highlighting for code now works in Authorea (rendered HTML) and in the exported PDF.

    This is what you need to do:

    1. Create a new LaTeX document

    2. Change your backend renderer to be LaTeXML. Article settings - More Preferences - LaTeXML

    3. Add the line \usepackage{listings} in your header.tex file

    4. Use the listings command to print your code

    Here’s an example of some Python code:

    #!/usr/bin/env python
    import socket
    import subprocess
    import sys
    from datetime import datetime
    
    # Clear the screen
    subprocess.call(`clear', shell=True)
    
    # Ask for input
    remoteServer    = raw_input(``Enter a remote host to scan: '')
    remoteServerIP  = socket.gethostbyname(remoteServer)
    
    # Print a nice banner with information on which host we are about to scan
    print ``-" * 60
    print ``Please wait, scanning remote host", remoteServerIP
    print ``-" * 60
    
    # Check what time the scan started
    t1 = datetime.now()