Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I generate latex with the following format in latex? I know about tex4ht and I know about latex4html but couldn't get similar output.

Source Website is here and a snapshot from the page is given below

enter image description here

Sample Tex File (Notice the tables in the above link)

\documentclass[ebook,10pt,oneside,openany,final]{memoir}

\usepackage[american]
           {babel}        % needed for iso dates
\usepackage[iso,american]
           {isodate}      % use iso format for dates
\usepackage[final]
           {listings}     % code listings


\setcounter{totalnumber}{10}

% Base definitions for tables
\newenvironment{TableBase}
{
 \renewcommand{\tcode}[1]{{\CodeStylex{##1}}}
 \newcommand{\topline}{}
 \newcommand{\capsep}{}
 \newcommand{\rowsep}{}
 \newcommand{\bottomline}{}

%% vertical alignment
 \newcommand{\rb}[1]{\raisebox{1.5ex}[0pt]{##1}}    % move argument up half a row

%% header helpers
 \newcommand{\hdstyle}[1]{\textbf{##1}}             % set header style
 \newcommand{\Head}[3]{\multicolumn{##1}{##2}{\hdstyle{##3}}}   % add title spanning multiple columns
 \newcommand{\lhdrx}[2]{\Head{##1}{|c}{##2}}        % set header for left column spanning #1 columns
 \newcommand{\chdrx}[2]{\Head{##1}{c}{##2}}         % set header for center column spanning #1 columns
 \newcommand{\rhdrx}[2]{\Head{##1}{c|}{##2}}        % set header for right column spanning #1 columns
 \newcommand{\ohdrx}[2]{\Head{##1}{|c|}{##2}}       % set header for only column spanning #1 columns
 \newcommand{\lhdr}[1]{\lhdrx{1}{##1}}              % set header for single left column
 \newcommand{\chdr}[1]{\chdrx{1}{##1}}              % set header for single center column
 \newcommand{\rhdr}[1]{\rhdrx{1}{##1}}              % set header for single right column
 \newcommand{\ohdr}[1]{\ohdrx{1}{##1}}
 \newcommand{\br}{\hfill\break}                     % force newline within table entry

%% column styles
 \newcolumntype{x}[1]{>{\raggedright\let\\=\tabularnewline}p{##1}}  % word-wrapped ragged-right
                                                                    % column, width specified by #1
 % \newcolumntype{m}[1]{>{\CodeStyle}l{##1}}              % variable width column, all entries in CodeStyle
 \newcolumntype{m}[1]{l{##1}}                           % variable width column, all entries in CodeStyle
}
{
}

% General Usage: TITLE is the title of the table, XREF is the
% cross-reference for the table. LAYOUT is a sequence of column
% type specifiers (e.g. cp{1.0}c), without '|' for the left edge
% or right edge.

% usage: \begin{floattablebase}{TITLE}{XREF}{COLUMNS}{PLACEMENT}
% produces floating table, location determined within limits
% by LaTeX.
\newenvironment{floattablebase}[4]
{
 \begin{TableBase}
 \begin{table}[#4]
 \caption{\label{#2}#1}
 \begin{center}
 \begin{tabular}{|#3|}
}
{
 \bottomline
 \end{tabular}
 \end{center}
 \end{table}
 \end{TableBase}
}

% usage: \begin{floattable}{TITLE}{XREF}{COLUMNS}
% produces floating table, location determined within limits
% by LaTeX.
\newenvironment{floattable}[3]
{
 \begin{floattablebase}{#1}{#2}{#3}{htbp}
}
{
 \end{floattablebase}
}


\newcommand{\CodeStylex}[1]{\texttt{#1}}
\newcommand{\tcode}[1]{\CodeStylex{#1}}

\begin{document}
\begin{floattable}
{Potential \tcode{setlocale} data races}
{tab:setlocale.data.races}
{lllll}
\topline

\tcode{fprintf}     &
\tcode{isprint}     &
\tcode{iswdigit}    &
\tcode{localeconv}  &
\tcode{tolower}     \\

\end{floattable}

\end{document}
share|improve this question
1  
Which aspect of that site is the one you want? The "plain text" formatting? The fixed-width font? The underlines in the titles? The bracketed [labels] at the sections? Why use latex if the result is not intended for printing? It looks as if nroff or texinfo, or markdown were better alternatives. –  JLDiaz Dec 4 '12 at 15:07
    
actually all of it :). –  RamneekHanda Dec 4 '12 at 15:11
1  
Looking at the source code of those pages, you can discover that all the content is basically pre-formatted and included in a big <pre> tag. It looks as if it was written directly in plain text, or processed with nroff. I can't see any relationship with LaTeX. Perhaps you can take some ideas from rfc-editor.org/formatting.html –  JLDiaz Dec 4 '12 at 15:17
    
You can get an nroff editor aaa-sec.com/nroffedit. LaTeX unfortunately cannot be used for badly formatted text, except under duress:) –  Yiannis Lazarides Dec 4 '12 at 16:41
    
unfortunately i have tex files.. so i need something that can convert stuff.. –  RamneekHanda Dec 4 '12 at 16:46
show 5 more comments

1 Answer

up vote 4 down vote accepted

This code relates to project which OP mentioned in the comments.

I would convert files with macro definitions to sty files. So rename files macros.tex, layout.tex, etc. to macros.sty etc. In your main file, call them then with \usepackage. Thanks of that, you can then provide configuration files for tex4ht.

You should rewrite some macros, to be easier for modification. for example. you have in macros.tex this macro:

\def\Sec#1[#2]#3{{%
\ifcase#1\let\s=\chapter
      \or\let\s=\section
      \or\let\s=\subsection
      \or\let\s=\subsubsection
      \or\let\s=\paragraph
      \or\let\s=\subparagraph
      \fi%
\s[#3]{#3\hfill[#2]}\label{#2}}}

As with tex4ht you will need to insert there some html tags, it would be better to modify it little bit:

\def\Sec#1[#2]#3{{%
\ifcase#1\let\s=\chapter
      \or\let\s=\section
      \or\let\s=\subsection
      \or\let\s=\subsubsection
      \or\let\s=\paragraph
      \or\let\s=\subparagraph
      \fi%
      \s[#3]{\SecParts{#3}{#2}}\edef\@currentlabel{_#2_}\label{#2}}}


\newcommand\SecParts[2]{#1\hfill[#2]}

Now you need only to redefine \SecParts macro in your tex4ht config file to insert some html tags. \edef\@currentlabel{_#2_} is here because you wanted cross-references with labels and underscores instead of section numbers.

I created configuration file macros.4ht, where I put some redefinitions:

% hooks definitions 

\NewConfigure{SecParts}{3}
\renewcommand\SecParts[2]{\a:SecParts#1\b:SecParts#2\c:SecParts}

\NewConfigure{Pnum}{2}
\def\pnum{\addtocounter{Paras}{1}\noindent\a:Pnum\arabic{Paras}\b:Pnum}

\Configure{SecParts}{}{\HCode{<span class="SecLabel">[}}{\HCode{]</span>}}
\Configure{Pnum}{\HCode{<span class="pnum">}}{\HCode{</span>}}

\Css{
body{
  width:60em;
  margin-left:4em;
  font-family:monospace;
}}

\Css{
 h1, h2, h3{font-size:1em;font-weight:normal;}
}
\Css{h2 br{display:none}}
\Css{
.titlemark{display:inline-block;margin-right:.5em;margin-left:0;}
}
\Css{
 p{
     text-align:justify;
     -webkit-hyphens: auto;
     -moz-hyphens: auto;
     hyphens: auto;
}    
}
\Css{.pnum{
display:block; width: 2em; margin-left:-2em; float:left;
}}
\Css{.SecLabel{
  display:block;
  float:right;
}
}
\Hinput{macros.sty}

With \NewConfigure commands I created configurable hooks, then with \renewcommand I redefined commands where I need to put these hooks. I think you have many macros, where you should use similar redefinitions for inserting html tags, so you can do that this way.

And major part of this file are css definitions which affects appearance.

enter image description here

share|improve this answer
    
thanks.. will have a look at it later tonight and accept the answer.. i have really made progress thanks to your knowledge :).. –  RamneekHanda Dec 12 '12 at 8:12
    
a quick question though.. is it the complete solution or will i have to go about learning what you have done and replicate it for other sty files? –  RamneekHanda Dec 12 '12 at 8:13
    
@RamneekHanda it is complete solution for general layout, I think. But you will probably want and need to adapt some document markup macros, to be able to assign html tags for their content and to be able to apply CSS styling –  michal.h21 Dec 12 '12 at 8:52
    
Perfect.. though i still get this warning and if i keep pressing ctrl-D.. it eventually does create the document in the form expected... can you help me solve this warning - (./utilities.aux ! Missing \endcsname inserted. <to be read again> \unhbox l.811 ...LiNK{x1-669000_time.traits.is_fp_}{750}}} –  RamneekHanda Dec 14 '12 at 16:21
    
@RamneekHanda I don't know what is the problem, maybe there is some problem with underscore? I know that tex4ht is playing with underscore catcodes –  michal.h21 Dec 14 '12 at 17:02
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.