2

Consider the following pseudocode:

\documentclass{article}%

\usepackage{etoolbox}%
\usepackage{enumitem}%

% BASIC QUALIFICATIONS
\listadd\qualifications{A degree}%
\listadd\qualifications{Skill}%
\listadd\qualifications{Common sense}%
\listadd\qualifications{Enthusiasm}%

\begin{document}

% duties
\section*{Basic Qualifications}

% opening call for function which facilitates export of section (or subsection) contents
% <here>
% \begin{export}[include section title=true]{qualifications.txt}


The successful candidate will have the following basic qualifications:

\begin{itemize}[topsep=2mm]
\forlistloop{\item}{\qualifications}
\end{itemize}

% closing call for
% \end{export}

\end{document}

The goal is to export the contents of a section (or subsection, subsubsection, etc.) to a .txt file without markup. Any suggestions as to the appropriate starting point are greatly appreciated.

0
1

TeX4ht can slice the generated HTML to separate HTML files for each section or subsection. These HTML files can then be converted to TXT using w3m or other text based browser.

To automate this, you can use the following Lua build script:

local domfilter = require "make4ht-domfilter"
local mkutils = require "mkutils"
local process = domfilter {
function(dom)
  for _, crosslinks in ipairs(dom:query_selector(".crosslinks")) do
    crosslinks:remove_node()
  end
  return dom
end
}

Make:match("html$", process)
Make:match("html", function(filename, settings)
  local output_name = filename:gsub("html$", "txt")
  mkutils.execute("w3m -dump " .. filename .. " > " .. output_name)
end)

It removes links to previous and next file that TeX4ht inserts automatically and converts each HTML file to TXT using w3m.

Compile your file using:

make4ht -e build.lua main.tex "3,sec-filename"

It will produce two TXT files, "sample.txt" and "BasicQualifications.txt". Names of files for sections are based on section titles. "sample.txt" contains just table of contents. "BasicQualifications.txt" looks like this:

Basic Qualifications

The successful candidate will have the following basic qualifications:

  * A degree
  * Skill
  * Common sense
  * Enthusiasm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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