Skip to content

More robust filename and extension parsing #457

@muzimuzhi

Description

@muzimuzhi

(originally found by @T-F-S in https://tex.stackexchange.com/a/750935)

Currently for \inputminted[<options>]{<language>}{<filename>}, minted treats

  1. everything in <filename> after the first / as the base filename, and
  2. everything in the base filename after the first . as file extension

minted/latex/minted/minted.dtx

Lines 3971 to 3992 in 19ea6fc

\gdef\minted@iffasthighlightmode@buffertempfile@i#1/#2\FV@Sentinel{%
\if\relax\detokenize{#2}\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\minted@iffasthighlightmode@buffertempfile@ii#1.\FV@Sentinel}%
{\minted@iffasthighlightmode@buffertempfile@i#2\FV@Sentinel}}
\gdef\minted@iffasthighlightmode@buffertempfile@ii#1.#2\FV@Sentinel{%
\if\relax\detokenize{#2}\relax
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{\minted@iffasthighlightmode@buffertempfile@iii#2\FV@Sentinel}}
\gdef\minted@iffasthighlightmode@buffertempfile@iii#1.\FV@Sentinel{%
\ifcsname minted@buffertempfileextension@#1\endcsname
\expandafter\@firstofone
\else
\expandafter\@gobble
\fi
{\minted@iffasthighlightmode@buffertempfile@iv}}

When <filename> contains multiple /s, in parsing for the base filename, it's more robust to find everything after the last, not the first /.

When the base filename contains multiple .s, for example \jobname.tcb.temp, the primary file extension might be more meaningful to minted (the .temp part), rather than the full file extension (the .tcb.temp part).

The expl3 function \file_parse_full_name:nNNN {<full name>} <dir> <name> <ext> fits exactly the requirements here. If non-expl3 catcode scheme is preferred, \UseName{file_parse_full_name:nNNN}... can be used instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions