Snippets

Alex Hogen LaTeX to Creole Wiki Conversion Script

Created by Alex Hogen
#!/usr/bin/python

#########################################################
# Author: Alex Hogen
# Created: April 14, 2016
# Last updated: April 14, 2016
#
# This code is not fully functinal. It is only the start 
# of an idea I have, but I don't have time to finish it 
# right now.
#
# Ideally, this script will be able to convert LaTeX
# sections to Creole headings, convert basic tables and
# bulleted/itemized lists. Nothing too fancy. Just a way
# to use existing LaTeX documentation in WIKIs instead of
# trying to convert everything yourself...
########################################################

# Used to extract file name from file path
import ntpath


latex_file_path = input("Enter the path to the input LaTeX file: ")

# Check to make sure file has the expected extention
if latex_file_path.endswith('.TEX') or latex_file_path.endswith('.tex'):

    print("Beginning to convert ", latex_file_path, "\n")
    
    # Open the LaTeX file
    f_latex = open( latex_file_path, "r")
    
    # Open/create new Creole file in same directory as source file
    f_creole_name = ntpath.basename(latex_file_path);
    f_creole_path = latex_file_path.replace(f_creole_name, "");
    f_creole_name = f_creole_name.replace(".tex", ".wiki");
    f_creole_path = f_creole_path + f_creole_name;
    f_creole = open(f_creole_path, "w");
    
    # Priming read
    latex_line = f_latex.readline();
    
    while latex_line.find("\begin{document}") == -1:
        
        print("Searching for beginning of document body...");
        latex_line = f_latex.readline();
        
    print("Beginning of document body found at line ", f_latex.tell() );
    
    # Close the LaTeX file and the new Creole Wiki file
    f_latex.close();
    f_creole.close();

# Print error message if file extention is incorrect
else:
    print("\nERROR: Expecting a file ending with .tex extention.\n")

print("Exiting...")

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.