1

Is there a way to protect some part of a LaTeX-Code to avoid overwriting? (Cause I want to allocate the code to someone who shouldn't "touch" some parts of the source code.)

Edit:

% Begin: don't touch!!
\RequirePackage{fix-cm}
\documentclass[fontsize=8.5pt,DIV=calc]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{helvet}

\usepackage{geometry}
\geometry{a4paper,left=15mm,right=15mm, top=26mm, bottom=17mm} 

\renewcommand{\familydefault}{\sfdefault}
\usepackage{multicol} 
\usepackage{xcolor}

\usepackage{mdframed}   
\usepackage{paralist}    

\setlength\parindent{0pt}
\setlength\columnsep{5mm}

\renewcommand\familydefault{\sfdefault}
\renewcommand{\labelitemi}{\textcolor{black!60}{\raisebox{0.5mm}{\rule{1.8mm}{1.8mm}}}}
\newcommand{\zitiert}[1]{\flqq{#1}\frqq}

\usepackage{enumitem}
\setitemize{leftmargin=*}

\addtokomafont{section}{\large}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{section}
    {\setlength\fboxsep{1.75mm}%
      \colorbox{black!15}{\raisebox{0pt}[\height][0pt]{%
        \parbox[b]{\dimexpr\linewidth-2\fboxsep\relax}{%
          \raggedsection\@hangfrom{\hskip#2#3}{#4}%
    }}}}
    {\@hangfrom{\hskip#2#3}{#4}}%
}
\renewcommand\sectionformat{%
  \makebox[10mm][r]{\thesection\autodot\hspace{5mm}}
}
\makeatother

% End: don't touch!!

\usepackage{lipsum}

\begin{document}
\begin{multicols}{2}
Some random text....
\lipsum[14]
\end{multicols}
\end{document}

The part from '% Begin: Don't touch!!' to '% End: Don't touch!!' should be "read-only"..

  • 3
    What do you mean with protect? Read-only files are a simple solution. – TeXnician Feb 10 '17 at 10:55
  • 1
    TeX code behaves like any other program code. It is stored in pure text files without any annotations. So no, it is not possible to protect parts of the code from modifications. But you can put the part that should not be modified into a separate file nottobemodified.tex and include it with \input{nottobemodified}. When the file is returned, you can use your original version of nottobemodified and also check with some text-comparision tool, whether your colleague's version is changed compared to yours. – gernot says Reinstate Monica Feb 10 '17 at 11:06
  • could you please add an example of what do you want to protect? – Timothy Truckle Feb 10 '17 at 11:06
  • Classical method: % Don't don't don't touch this part!). Or may be the opposite that gernot suggest: send tobemodified.tex while main.tex (with \input{tobemodified}) is not shared, or it is flagged as read-only in the OS and in the comments (e.g: % Don't don't don't edit this file !!!). – Fran Feb 10 '17 at 11:20
3
  1. Put the stuff between % Begin: don't touch!! and % End: don't touch!! into a file myclass.cls.
  2. In myclass.cls, replace \documentclass by \LoadClass and \usepackage by \RequirePackage.
  3. In myclass.cls, remove \makeatletter and \makeatother.

Now myclass.cls looks as follows:

\RequirePackage{fix-cm}
\LoadClass[fontsize=8.5pt,DIV=calc]{scrbook}
\RequirePackage[T1]{fontenc}
\RequirePackage[ngerman]{babel}
\RequirePackage[utf8]{inputenc}
\RequirePackage{helvet}

\RequirePackage{geometry}
\geometry{a4paper,left=15mm,right=15mm, top=26mm, bottom=17mm} 

\renewcommand{\familydefault}{\sfdefault}
\RequirePackage{multicol} 
\RequirePackage{xcolor}

\RequirePackage{mdframed}   
\RequirePackage{paralist}    

\setlength\parindent{0pt}
\setlength\columnsep{5mm}

\renewcommand\familydefault{\sfdefault}
\renewcommand{\labelitemi}{\textcolor{black!60}{\raisebox{0.5mm}{\rule{1.8mm}{1.8mm}}}}
\newcommand{\zitiert}[1]{\flqq{#1}\frqq}

\RequirePackage{enumitem}
\setitemize{leftmargin=*}

\addtokomafont{section}{\large}
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{section}
    {\setlength\fboxsep{1.75mm}%
      \colorbox{black!15}{\raisebox{0pt}[\height][0pt]{%
        \parbox[b]{\dimexpr\linewidth-2\fboxsep\relax}{%
          \raggedsection\@hangfrom{\hskip#2#3}{#4}%
    }}}}
    {\@hangfrom{\hskip#2#3}{#4}}%
}
\renewcommand\sectionformat{%
  \makebox[10mm][r]{\thesection\autodot\hspace{5mm}}
}
  1. Change the original document to

    \documentclass{myclass}
    \usepackage{lipsum}
    \begin{document}
    \begin{multicols}{2}
    Some random text....
    \lipsum[14]
    \end{multicols}
    \end{document}
    

Then tell your colleague not to change myclass.cls, or just don't use his copy but yours.

  • This is a good way to solve my problem! Thank you:) – GuestUser Feb 10 '17 at 11:56
  • 1
    Don't forget to add a license to the class. You can use one, that does not allow changes without changing the identifiers, e.g., lppl. ;-) – Schweinebacke Feb 10 '17 at 12:11

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.