2

I'm currently working on a document with LaTeX and I want to make all sectioning in a separate document.

On main.tex I have the following

\documentclass[fontsize=12pt, fonttype=arial]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[catalan, activeacute]{babel}
\usepackage{currfile}

\begin{document}

\tableofcontents \newpage \input{Composició de la matèria} %On the future I will have more \input with more sections

\end{document}

And on "Composició de la matèria.tex" I have this

\section{\currfilebase}
%On the future I will have more text here

But the pdf output it's the following

Table of contents Table of contents, has the proper output

The section The section, doesn't have the proper output

It happens with all the catalan acutes, how could I do it?

TheRepSter
  • 23
  • 3
  • Welcome to TeX.SX! It is an interesting idea, but is it really necessary that the file name is exactly the section title in the file? Just being curious ... – Jasper Habicht Nov 17 '21 at 12:41
  • 2
    I wouldn't do that, file names and section titles are quite different things and should be set independantly. What will you do if you want a superscript or some math or some latex command in the title ? – Ulrike Fischer Nov 17 '21 at 13:09

1 Answers1

2

I don't think there's much to gain with this approach.

Anyway, the problem is that \currfilebase is stored as a string (all characters receive category code 12) and so utf8 cannot do its translation job.

Here's a patch that also stores a “normal characters” version of \currfilebase, called \utfcurrfilebase.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[catalan]{babel}
\usepackage{currfile}
\usepackage{xpatch}

\makeatletter \xpatchcmd{\currfile@set} {\global\let\currfilebase\filename@base} {\global\let\currfilebase\filename@base\makeutf@currfilebase} {}{} \makeatother

\ExplSyntaxOn \cs_new_protected:cpn { makeutf@currfilebase } { \tl_gset_rescan:Nnx \utfcurrfilebase {} { \currfilebase } } \ExplSyntaxOff

\begin{document}

\tableofcontents \input{Composició de la matèria}

\end{document}

The included file should use \utfcurrfilebase:

\section{\utfcurrfilebase}

enter image description here

egreg
  • 1,121,712