1

I'm learning LaTex but have a strong programming background. My document consist of several .tex files I will \input at entry .tex file. I would like to add a lettrine to every one of them, but would rather not edit the separate .tex files. Instead, I would love if I could, somehow, get the first word of the file, then get the first letter of that first word, and then dynamically insert the lettrine{H}{eya} and append the rest of the file.

Is there any way to do this? Thanks!

EDIT:

In addition, I'm using a new command to perform certain operations before actually inputting the file, so the actual call to \input is done using a command argument, like this \input{#2}. The only answers solves my problem when calling input outside other command, but not inside the command.

1 Answers1

2

You can define

\def\dolettrine #1#2 {\lettrine{#1}{#2} }

and use

\expandafter \dolettrine \input file.tex

But, if you are using LaTeX then there are complications, because \input TeX primitive is redefined. So, you can do something like this:

\catcode`\@=11
\expandafter \dolettrine \@@input file.tex
wipet
  • 74,238
  • \def\dolettrine #1#2 {\lettrine{#1}{#2} } passes only the first two letters, and not the first letter and then the rest of the word. – Lorenzo Peña Feb 02 '16 at 17:52
  • @LorenzoPeña No. #1 is the first letter and #2 is the rest of the first word. Note that #1 is undelimited parameter and #2 is delimited parameter with space delimiter. Note the space after #2 declaration. – wipet Feb 02 '16 at 19:09
  • In addition, when using inside a \newcommand, it's advised to enclose the definition in \makeatletter and \makeatother, to make it work seamlessly. @wipet, please consider adding your comments regarding this, for the sake of completion. – Lorenzo Peña Feb 18 '16 at 14:33