Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In C#, we can specify certain properties of a class to be private, read only, etc. I want to apply this methodology in writing LaTeX document class if it is possible.

I can find articles pertaining to it neither on the internet nor in a book.

The following is my simplified document class.

\ProvidesClass{pst-xport}[a cute document class for my own purpose.]
% .... others ....

\RequirePackage{pstricks}

\newcommand\Left{-1}
\newcommand\Right{1}

\newlength\LeftPadding\setlength{\LeftPadding}{1cm}
\newlength\RightPadding\setlength{\RightPadding}{1cm}

% it must be private
\newlength\PictureWidth

\AtBeginDocument
{
    \setlength{\PictureWidth}{\dimexpr\Right\psxunit-\Left\psxunit\relax}
    \paperwidth=\dimexpr\PictureWidth+\RightPadding+\LeftPadding\relax
    % .... others ....
}


% .... others ....

% it must be private
\parindent=0pt

%%%%%%%%%%%%%%%%%%%%
%%%% INTERFACES %%%%
%%%%%%%%%%%%%%%%%%%%

\newcommand\SetPicture[2]
{
    \renewcommand\Left{#1}
    \renewcommand\Right{#3}
}


\newcommand\SetPadding[2]
{
    \setlength{\LeftPadding}{#1}
    \setlength{\RightPadding}{#3}
}

\newcommand\GetPaperWidth{\PictureWidth}
\endinput

We use this document class as follows.

\documentclass{pst-xport}

\SetPicture{-2}{2}
\SetPadding{0.5cm}{0.5cm}

% \parindent must not be accessible in this input file.
\parindent=10pt

% \PictureWidth must not be accessible in this input file.
\setlength{\PictureWidth}{10cm}

\begin{document}
\parbox{\GetPictureWidth}
{
    I can find a tool to convert
    PDF to EPS in my neither
    bathroom nor kitchen.
}
\end{document}

Questions

If it is possible, how to make certain macros defined in a document class inaccessible from outside?

share|improve this question
2  
I don't think there is a way to make truly private methods per se, but you are aware of the way @ works, right? It is override-able but is standardly used to make macros unavailable in normal documents. tex.stackexchange.com/questions/8351/… –  kgr Jul 27 '11 at 18:23
add comment

2 Answers 2

up vote 12 down vote accepted

You can't make macros totally inaccessible from "outside". Even the TeX primitives are not protected and can be redefined (their names, not their function). You can only give your macros a very special name to avoid accidental and hinder deliberate changes on them.

Usually internal macros which are not supposed to be changed by other code include an @ which is normally not allowed as part of a macro name. This can be changed using \makeatletter and changed back to normal with \makeatother. Also such internal macros of one package should start with an specific prefix which is normally build from the package name. So instead of naming an internal macro \foobar call it \xport@foobar. This won't protect it from some users which really want to change it, but they can consider themselves warned.

share|improve this answer
add comment

Also, you might want to explore expl3 (part of LaTeX3), which has its own naming conventions (quite distinct from plain TeX's and LaTeX2's @).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.