Consider the following pseudocode:



\listadd\qualifications{A degree}%
\listadd\qualifications{Common sense}%


% 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:


% closing call for
% \end{export}


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.


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 {
  for _, crosslinks in ipairs(dom:query_selector(".crosslinks")) do
  return dom

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

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.