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!


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.


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:

\expandafter \dolettrine \@@input file.tex
  • \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 2 '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 2 '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

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.