Regular Expressions: Using Perl to Convert HTML to Latex

1 hour
  • 2 Learning Objectives

About this Hands-on Lab

Perl and regex go so well together one of the most popular and common regex types is called Perl-Compatible Regular Expressions. In this hands-on lab, we’re going to write a reusable script that can convert HTML documents to Latex using Perl and Perl-based regular expressions.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Craft a script to convert HTML to Latex.

Using Perl, create a script that will convert any HTML documentation to Latex using the standards provided in the instructions.

Convert `regexcs.html` to Latex.

Convert the provided HTML file to Latex; save as regexcs.latex.

Additional Resources

EtherCloud's internal documentation system is no longer working! As the web hosting company grows, keeping documentation in a self-maintained website is no longer working. Instead, it's been requested that documents are written in Latex so they can be added to a proper documentation repository. The only problem is what to do with the existing documents. By using the provided regex cheat sheet document, craft a Perl script to convert all existing HTML documents to Latex.

If you're unfamiliar with Latex, use the following table to determine how to precede:

HTML TagLatex
H1title{TITLE}
H2section{SECTIONNAME}
H3subsection{SECTIONNAME}
Unordered Listsbegin{itemize} AND end{itemize}
List itemsitem
Italicstextit{TEXT}
Inline codetexttt{TEXT}
Code blocksbegin{verbatim} AND end{verbatim}

Additionally, all documents must start with:

documentclass{article}
usepackage{hyperref}
begin{document}

And end with:

end{document}

Note that if you're having trouble getting any backslashes to show up in your output, use two backslashes in its place (i.e., s/<ul>/\begin{itemize}/).

Save the script as html-to-latex.pl. Run it against the regexcs.html file and save the resulting output as regexcs.latex.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!