I am trying to convert man pages to tex, and I keep getting \item[in the beginning of the file and] \hfill \\After the part of the man pages where it shows ENV(1L). Everything else seems to be working. This is my tex.sed:/^\<[A-Z]*[A-Z]/i \\\item[/^\<[A-Z]*[A-Z]/a \] \\hfill \\\\1i\\\documentstyle[11pt]{article} \\\begin{document}1i\\\begin{center} {\\bf 1a\\} \\end{center}2i\\\begin{description}$a\\\end{description}$a\\\end{document}s/\\/\\verb\+\\\+/gs/%/\\%/gs/\^/\\\^/gs/--/-\\hspace\{.01cm\}-/gs/^+/ \\\\/s/^-/ \\\\/Here is env.ascii:ENV(1L)NAME      env - run a program in a modified environmentSYNOPSIS      env    [-]    [-i]    [-u   name]   [--ignore-environment]      [--unset=name] [name=value]... [command [args...]]DESCRIPTION      This manual page documents the GNU version  of  env.   env      runs  a  command with an environment modified as specified      by the command line  arguments.   Arguments  of  the  form      `variable=value'  set the environment variablevariable to      valuevalue.  value may be empty (`variable=').  Setting a      variable to an empty value is different from unsetting it.      The  first  remaining  argument  specifies  a  program  to      invoke;  it is searched for according to the specification      of the PATH environment variable.  Any arguments following      that are passed as arguments to that program.      If  no command name is specified following the environment      specifications,  the  resulting  environment  is  printed.      This is like specifying a command name of `printenv'.OPTIONS     -u, --unset name             Remove  variable name  from the environment, if it             was in the environment.     -, -i, --ignore-environment             Start  with  an  empty  environment,  ignoring  the             inherited environment.      The  long-named options can be introduced with `+' as well      as `--', for compatibility with previous releases.         Eventually  support  for  `+'  will  be removed, because it       is incompatible with the POSIX.2 standard.And this is how I am compiling: sed -f tex.sed env.ascii > env.texThis is what my env.tex looks like:\documentstyle[11pt]{article} \begin{document}\begin{center} {\bf \item[ENV(1L)] \hfill \\} \end{center}\begin{description}\item[NAME] \hfill \\      env - run a program in a modified environment\item[SYNOPSIS] \hfill \\      env    [-]    [-i]    [-u   name]   [-\hspace{.01cm}-ignore-environment]      [-\hspace{.01cm}-unset=name] [name=value]... [command [args...]]\item[DESCRIPTION] \hfill \\      This manual page documents the GNU version  of  env.   env      runs  a  command with an environment modified as specified      by the command line  arguments.   Arguments  of  the  form      `variable=value'  set the environment variablevariable to      valuevalue.  value may be empty (`variable=').  Setting a      variable to an empty value is different from unsetting it.      The  first  remaining  argument  specifies  a  program  to      invoke;  it is searched for according to the specification      of the PATH environment variable.  Any arguments following      that are passed as arguments to that program.      If  no command name is specified following the environment      specifications,  the  resulting  environment  is  printed.      This is like specifying a command name of `printenv'.\item[OPTIONS] \hfill \\     -u, --unset name             Remove  variable name  from the environment, if it             was in the environment.     -, -i, --ignore-environment             Start  with  an  empty  environment,  ignoring  the             inherited environment.      The  long-named options can be introduced with `+' as well      as `-\hspace{.01cm}-', for compatibility with previous releases.         Eventually  support  for  `+'  will  be removed, because it       is incompatible with the POSIX.2 standard.\end{description}\end{document}NoteThe end result must be a sed script that correctly converts the man page to a .tex file. Please don't suggest answers with a different approach to the problem.
Sed script inserting and appending in wrong place only in one particular place
sed;conversion;latex;ascii
If your desired result is just the man pages in PDF format, man itself can do this for you. You will need the ghostscript suite of tools and you can do the following, for example, to get the bash(1) page in PDF format:man -T ps bash|ps2pdf - bash.pdfIf you were intending to use LaTeX to produce DVI man pages, you won't need ghostscript as man can do this directly:man -T dvi bash >bash.dviQuoted verbatim from Bichoy's commentThe -T ps option is not portable for man. On RHEL6, the correct syntax will be man -t bash, the -t option makes the output as ps using /usr/bin/groff -Tps -mandocA few notes about the sed scriptWhat worked for me is moving the first 6 lines of your script after the \\begin{center} line. Please try it and see if this is the desired result.You should put considerable effort into escaping special characters in the content of the man page(s). Your script currently escapes some of them but there's always a chance you're forgetting one or another. I can tell you at least forgot to escape ampersands (&) which (La)TeX uses as column separators. This is why umlute and I have been suggesting an alternate approach to TeXifying the whole thing yourself.Is the beginning of your document a typo or is it actually supposed to be \\documentstyle as opposed to \\documentclass?To exclude the command name from being surrounded by \item tags, you should change your regex to match a word consisting entirely of uppercase letters: change \<[A-Z]*[A-Z] to something like ^\s*[A-Z][A-Z]*\s*$.