[Tex/LaTex] I have a dream: Using CSS to style a TeX document

csspackage-writing

I have no clue in LaTeX package developing but I have a dream! Consider following two files:

% A LaTeX file
\documentclass{article}
\usepackage[style.css]{css}

\begin{document}
\begin{abstract}
  This is abstract!
\end{abstract}
  This is \cls{code}{foo} and that is \cls{code}{bar}.
\end{document}

A simple css.file:

/*style.css*/
abstract{
  color:red;
}

.code{
 background:blue;
}

I want the package map css rules to its latex counterparts before rendering. In this example:

\documentclass{article}
\usepackage{color}

\begin{document}
{\color{red}
\begin{abstract}
   This is abstract!
\end{abstract}
}
This is \colorbox{blue}{foo} and that is \colorbox{blue}{bar}.
\end{document}

I want to know how can I develop a simple package that for beginning provide ability to use color/font-family/font-weight css rules in LaTeX. In next stage I want to add it id/class addressing. Perhaps we can put the source in GitHub and the community could extend it.

Notice that I want to use only CSS syntax as syntax-suger for LaTeX styling.

As an answer please at least provide a minimum solution to set the color of abstract using provided example. Thanks all.

related:
CSS based LaTeX formatting?

Best Answer

TeX is an extremely powerful typesetting system. While TeX can be used to make toast or control a Mars rover writing complex programs in TeX/LaTeX is generally more difficult than languages like C, Perl, and Python. In order to parse your example CSS

\*style.css*    abstract{
  color:red;
}

.code{
 background:blue;
}

you would likely have to either make a and . active or process it with regular expressions. As @JosephWright told explained to me in a comment to this answer

We do have regex support in LaTex3, but it's truly 'regular', so many of the things the PCRE can do are out. Performance is also an issue if you want to use it for large-scale work.

I would suggest instead of doing the conversion directly in TeX you use Perl (or a programming language of your choice) to write a program like css2sty which would use a powerful regular expression engine to do the conversion.

Related Question