【问题标题】:Converting a LaTeX document to html using sed commands?使用 sed 命令将 LaTeX 文档转换为 html?
【发布时间】:2015-02-09 05:27:21
【问题描述】:

我的任务是使用 sed 命令将 LaTeX 文档转换为 html。我已经将我目前拥有的命令放入一个 sedscript 文件中,它们都可以一次在 LaTeX 文件上执行。 LaTeX 文档代码目前看起来像这样(到目前为止,使用 sedscript 文件已在其上执行的命令):

<HTML> 
 <HEAD>
\TEST TITLE{Capture of colour pictures using visilog}
\author{Neal Snooke}
<BODY>
\makeTEST TITLE

\section{Introduction}

It is possible to use Zeus and the visilog software to capture 
colour images.  Because of the 8 bit deep frame buffer the 
procedure is divided into several stages, explained in the next sections.
The captured pictures can be converted in to almost any format. eg.
PPM, TIFF, GIF etc.

\section{Process overview}

The entire process is divided into the following stages:
\begin{itemize}
\item set up the hardware
\item capture red, green and blue image components
\item combine the RGB files and convert from visilog to a
      more useful single file format
\item adjust the colour balance and quantize the colour palette
\item store in the format of your choice
\end{itemize}

\section{Set up the hardware}

Make sure the following have been performed:
\begin{itemize}
\item login to Zeus do not run Xwindows !
\item Make sure the RGB and sync leads from the colour camera are connected
      to the small grey box (sync generator)
\item Make sure the RGB leads from the sync generator lead to
      channels 1, 2, and 3 (red, green, blue {\em resp}) on the frame
      buffer card on Zeus.  
\item Turn on the camera power supply and sync generator.  The sync generator
      requires a 9V battery to operate.
\item Turn on the secondary colour monitor next to Zeus 
\end{itemize}

\section{Image capture}

To run visilog you must be in the Suntools window system. Visilog must
also be run from the correct directory.
\begin{verbatim}
Zeus: Suntools

Zeus: cd /usr/local/visilog/monitor
Zeus: visilog
\end{verbatim}

If all is well the main visilog window will occupy most of the main
monitor.  Click on the `:256' icon and select an image size of 512.

To test the camera click on the `GRAB' icon select channel 2, quadrant 4,
and and name, a live video picture will appear on the secondary monitor. 
Answer the `freeze frame' question with your choice (does not matter). 
If no image appears check the brightness controls, camera RGB leads,
power supply and sync box battery (green led should be lit). 

The strategy now is to capture 3 images, one from each channel, and
then store them to 3 files called `red.cam', `green.cam', `blue,cam'.
It is a good idea to change directory to your home filestore, or failing
that /tmp will do.  To do this click on the `chd' selection from the
`utilities' menu (default).

A file exists that will force visilog to automatically capture the 
required images and write them to the current directory.  Available
from {\bf ~nns/vlog/capture.j}. Click on the `PLAY' selection and specify
this file.  Visilog will prompt for continuous or step by step play, -
if the first image flickers when using continuous then use step-by-step.
(continuous usually works, but not always ??)

\section{Image Conversion}

Assuming you now have three files (called `red.cam', `green.cam', `blue.cam'
these should be 262144 bytes each) you can run a small program called
{\bf ~nns/vlog/cam2ppm} to merge these into a single file which will be 
in the .PPM
format.  You will need another shell window to perform the conversion.
\begin{verbatim}
MACHINE% cam2ppm > myfile.ppm
\end{verbatim}

Theoretically the image is now ready for use.  However it will usually
have slightly odd colour characteristics, due to the lighting etc.  Also
the 24 bit colour will need to be quantized to 8 bits for most displays.

The best way to achieve this is to use {\bf xv}.  Load the created image
and select `COL EDIT' where the colour components, intensity, contrast
etc can be adjusted via a very nice graphical interface.
The file can subsequently
be written in the format of your choice with the 'SAVE' menu.  The image
can also be cropped if the edges are poor.

The output file will be considerably smaller (PPM, GIF, TIFF) due to the colour 
quantization performed by {\bf xv}.  Beware of postscript as the resulting file
could be MASSIVE 1-2Mb.

As {\bf xv} cannot be run in sunview (!) you must either quit visilog and 
sunview
and run X or log on to another machine to play with the image.
 </BODY>

到目前为止,这是我的 sedscript:

1i\
 <HTML> \
 <HEAD>
s/\\begin{document}/<BODY>/
/\\end{document}/{
 i\
 <\/BODY>
 d
}
$a\
<P>document automatically converted from LaTeX to HTML

/title/{
s/title/TEST TITLE/
}

/\documentstyle/d

/\maketitle/d

我需要帮助使用 sed 命令对文档执行以下操作

-将 \title{} 更改为 &lt;HTML&gt; &lt;/HTML&gt;

-将 \section{} 更改为 &lt;H1&gt; &lt;/H1&gt;

-将 \author{} 更改为 &lt;B&gt; &lt;/B&gt;

-改变 \begin{itemize} \项目某事 \end{itemize}

<UL>
<LI>something
</UL>

-将 {\bf } 更改为 &lt;B&gt; &lt;/B&gt;

-将 {\em } 更改为 &lt;I&gt; &lt;/I&gt;

如果您能提供执行上述任务的任何 sed 命令,谢谢 :)!

【问题讨论】:

    标签: html linux sed


    【解决方案1】:

    我有更好的给你,试试命令

     latex2html
    

    查看http://www.ctan.org/pkg/latex2html/

    【讨论】:

    • 谢谢,我想我可以使用转换器,但它用于一个项目,所以我认为需要使用 sed 命令:(
    • 对于一个项目来说,如何让糟糕的重新发明轮子成为一个好主意?
    【解决方案2】:

    \section{} 更改为&lt;H1&gt; &lt;/H1&gt;

    s#\\section{\([^}]*\)}#<H1>\1</H1>#
    

    \author{} 更改为&lt;B&gt; &lt;/B&gt;

    s#\\author{\([^}]*\)}#<B>\1</B>#
    

    \begin{itemize} \item something \end{itemize} 更改为 &lt;UL&gt;&lt;LI&gt;something&lt;/UL&gt;(假设此代码中 begin 和 end 不在同一行)

    /\\begin{itemize}/,/\\end{itemize}/ {
       s/\\begin{itemize}/<UL>/
       s#\\end{itemize}#\
    </UL>#
       s/\\item /\
    <LI>/g
       }
    

    {\bf } 更改为&lt;B&gt; &lt;/B&gt;

    s#{\\bf \([^}]*\) }#<B>\1</B>#
    

    -将{\em } 更改为&lt;I&gt; &lt;/I&gt;

    s#{\\em \([^}]*\) }#<I>\1</I>#
    

    但主要关注的是所有可能的异常,如 \bf 中的{,为此我们应该添加所有那些在 Latex 中允许的管理。所以这是一个开始的基础。处理异常的一种方法是首先以临时格式翻译它(例如:\{ -> )完成工作并在之后将其翻译回来(并且至少需要 2 次翻译来处理异常协议本身 [the e 在这个示例中])

    【讨论】:

      猜你喜欢
      • 2020-12-21
      • 2021-07-25
      • 2016-08-26
      • 2010-10-23
      • 2017-09-06
      • 1970-01-01
      • 2012-04-23
      • 1970-01-01
      • 2021-09-11
      相关资源
      最近更新 更多