0

I was wondering, if it is possible using always the same Latex document for writing different letters without copying the whole folder with all the tex files. To begin a new Letter, I want to input one(!) single *.tex file that contains the new adress and(!) the new text. I could solve this issue by using two seperated files - but is ist possible to use just one single file that contains adress and text!?

%%% scrlttr2 
\input{praeambel}
\begin{letter}{%
\input{adress1}
%\input{adress2}
%
}
%%%
\input{text1.tex}
\%input{text2.tex}
%%%
\closing{Sincerely yours}
\end{letter}
\end{document}

Source for letter: “adress_and_text.tex”
%%% address 
\setkomavar{subject}{xxx}
\opening{Dear Mr. xxx}
%%%text
  • 1
    It sure is possible... You just have to replace the text and the address every time you are writing a new letter. Though I have the feeling that this is not what you have in mind. Could you elaborate what exactly it is you want to accomplish (e.g. your desired "workflow" to write a new letter). – Raven Sep 6 '18 at 9:35
  • Do you want a different subject every time? – TeXnician Sep 6 '18 at 10:07
  • It is not a bulk letter, where I have a list of people, that receive the same letter. I just wanna "reuse" the format style of the same letter everytime - old letters should be stored in the tex folder. – TRJW Sep 6 '18 at 11:12
2

Maybe you want:

\begin{filecontents*}{letter1.tex}
\begin{letter}{name 1\\address 1}
\setkomavar{subject}{xxx}
\opening{Dear Mr. xxx}
Text 1
\closing{Sincerely yours}
\end{letter}
\end{filecontents*}

\begin{filecontents*}{letter2.tex}
\begin{letter}{name 2\\address 2}
\setkomavar{subject}{yyy}
\opening{Dear Mr. yyy}
Text 2
\closing{Best regards}
\end{letter}
\end{filecontents*}

\documentclass{scrlttr2}
\begin{document}
\input{letter1}
\input{letter2}
\end{document}

or

\begin{filecontents*}{letterA.tex}
\setkomavar{address}{name A\\address A}
\setkomavar{subject}{xxx}
\opening{Dear Mr. xxx}
Text A
\closing{Sincerely yours}
\end{filecontents*}

\begin{filecontents*}{letterB.tex}
\setkomavar{address}{name B\\ address B}
\setkomavar{subject}{yyy}
\opening{Dear Mr. yyy}
Text B
\closing{Best regards}
\end{filecontents*}

\documentclass{scrlttr2}
\newkomavar{address}{}
\begin{document}
\begin{letter}{\usekomavar{address}}
  \input{letterA}
\end{letter}

\begin{letter}{\usekomavar{address}}
  \input{letterB}
\end{letter}
\end{document}
1

If I understand you correctly you want something like a bulk letter, so the following code should suit your needs.

You define the correspondents and the text in the preamble and then it will output the letters for each of the persons. Should you want a different text each time, simply use a fourth argument for \newletter and append it to the sequence. Then use it instead of \tl_use:N \g_trjw_text_tl.

\documentclass{scrlttr2}

\usepackage{xparse}
\ExplSyntaxOn
\seq_new:N \g_trjw_letters_seq
\tl_new:N \g_trjw_text_tl
\NewDocumentCommand { \newletter } { m m m }
    {
        \seq_gput_right:Nn \g_trjw_letters_seq
            {
                {#1}, {#2}, {#3}
            }
    }
\NewDocumentCommand { \settext } { +m }
    {
        \tl_gset:Nn \g_trjw_text_tl { #1 }
    }
\NewDocumentCommand { \typesetletters } { }
    {
        \seq_map_inline:Nn \g_trjw_letters_seq
            {
                \seq_set_from_clist:Nn \l_tmpa_seq { ##1 }
                \setkomavar { subject } { \seq_item:Nn \l_tmpa_seq { 1 } }
                \begin{letter} { \seq_item:Nn \l_tmpa_seq { 2 } }
                    \opening { Dear ~ Mr. ~ \seq_item:Nn \l_tmpa_seq { 3 } }
                    \tl_use:N \g_trjw_text_tl
                    \closing{Sincerely ~ yours}
                \end{letter}
            }
    }
\ExplSyntaxOff
\newletter{Subject}{Some\\ address}{Quack}
\newletter{Subject 2}{Some\\ other\\ address}{Quack2}
\settext{Some long text}

\begin{document}
\typesetletters
\end{document}

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.