3

Context:

In the text of a document I am planning I will have numerous "strings" that are in a foreign language (foreign to me of course).

My current plan is to use the glossaries package because it would allow me to:

  • create a custom type
  • add keys
  • treat the \gls{english name so I know what I am doing} as an easily maintained string.
  • As a foreign language I expect heavy corrections and a single location to maintain and fix these strings will be
  • treat the first usage like foreign quote (English translation)
    • for example: \gls{My land is rich} could easily produce

M'fhearann saidhbhir (My land is rich)

  • doesn't matter whether I am using individual words, or sentences or paragraphs, as long as I redefine what appearance the gls call formats the output with.

Based on an older question: Am I over exerting the glossaries package? I believe I could also use etoolbox to do something similar

 \newentry{My land is rich}{M'fhearann saidhbhir}
 and use it with 
 \entry{My land is rich} (My land is rich)

Problem: if the translation is what is wrong it will be an incorrect label in the TeX file, but can be corrected in the definitions file. This is what makes me wonder if someone has already written a package to address this kind of thing.

Conceptually, there are infinite approaches to manage data in the form of label replaced strings but ideally I still need to work with recognizable labels therefore things like \entry{T1} or \gls{T1} or \T1 (as could be created with \newcommand{}{}) wouldn't be helpful even though they strictly solve the problem.

I have seen some pretty dynamic looking packages so am wondering if things exist.

The only other not fully formed concept I have had is to consider redefining a new custom command that would contain something like \translate{T1}{my land is rich} where the second argument is useless, purely cosmetic for the author and any TeX savvy collaborator reviewing the files, and the T1 is the label that would populate using whatever package I am able to use i.e. glossaries or etoolbox

  • How about this: create a command-creator that defines a macro with a set of arguments, which you use in the file. So: \defmaker{richland}{My land is rich}{M'fhearann saidhbhir}; then you use in your file \richland, and that expands to the whichever string you want it to based on some boolean switch. Then you'd also have other ones like \defmaker{poorland}{My land is poor}{M'fhear kasjdfois} which you use as \poorland, and so on.... But I don't really understand what you want, so this may be a bad idea. – jon Jun 27 '15 at 22:53
  • @jon thanks for the thought. This is the same approach that I proposed at the end just with a possible implementation. If you want to include it as an answer I will up vote and depending on what possibilities and alternatives trickle in will consider as a solution. A complete answer can't possibly highlight all expandable and integratable possibilities, so if you could point out limitations to its scope it would increase its value. Thanks! – EngBIRD Jun 27 '15 at 23:03
3

The idea here is to create a command, \myterm, which creates other commands based on its first argument; these created commands can then be used in the document, and will expand to either one string or another based on your settings.

\documentclass{article}
\usepackage{filecontents}
% The terminology.sty file % -----------------------------------------
\begin{filecontents*}{terminology.sty}
\def\termfileversion{0.01}
\def\termfiledate{2015/06/27}
%
%
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{terminology}
  [\termfiledate{} v\termfileversion{} Commands for technical terminology]


\RequirePackage{etoolbox}
\RequirePackage{xcolor}
\RequirePackage{xparse}

% When "proofing" text, highlight words
\definecolor{proofcol}{cmyk}{0,   0.87, 1,    0.21}


% Boolean switches
\providebool{proof}
\providebool{latin}

% Macro-maker:
% #1 = \macro
% #2 = {Latin string}
% #3 = [Latin root]
% #4 = {English string}
% #5 = [English root]
%
% Note: #3 and #5 might be useful if you want to create plural
% variants that can be related back to the singular forms; though this
% would require extending the \myterm macro
%
\NewDocumentCommand{\myterm}{mmomo}
{%
  % The optional command (##2) here overrides the defaults
  % The star (##1) means it will print the "original" in parenthesis
  \expandafter\NewDocumentCommand\csname#1\endcsname{so}%
  {%
    % We want to be able to use the Latin or the English
    \ifbool{latin}%
    {% latin = true
      \IfNoValueTF{##2}%
      {\p@col{#2}}%
      {\p@col{##2}}%
      \IfBooleanTF{##1}%
      {\space \showorig{#4}}%
      {\relax}%
    }%
    {% latin = false
      \IfNoValueTF{##2}%
      {\p@col{#4}}%
      {\p@col{##2}}%
      \IfBooleanTF{##1}%
      {\space \showorig{#2}}%
      {\relax}%
  }%
}%
}%

% Helper macros
\newcommand{\showorig}[1]{(\emph{#1})}
\newcommand{\p@col}[1]{%
  \ifbool{proof}%
  {\textcolor{proofcol}{#1}}%
  {#1}%
}


% Now some  definitions:
\myterm{useright}{usus iuris}{use of right}
\myterm{rightuse}{ius utendi}{right of using}
\myterm{rightsuse}{iura utendi}[ius utendi]{rights of using}[right of using]

\endinput
\end{filecontents*}% -------------------------------------------------

\usepackage[T1]{fontenc}
\usepackage{terminology}


\begin{document}
\parindent 0pt

\booltrue{latin}

\verb|\useright:| \useright

\verb|\rightuse:| \rightuse

\verb|\rightuse:| \rightsuse

\booltrue{proof} % Putting things in colour

\verb|\rightsuse:| \rightsuse[not wrongs of using]

\verb|\rightsuse:| \rightsuse*[not wrongs of using]

% Switch to using English
\boolfalse{latin}

\verb|\useright:| \useright*

\verb|\rightuse:| \rightuse

\verb|\rightuse:| \rightsuse

\boolfalse{proof} % No colour...

\verb|\rightsuse:| \rightsuse[not wrongs of using]

\verb|\rightsuse:| \rightsuse*[not wrongs of using]

\end{document}

One advantage of this approach is that you could "enrich" the \myterm macro so it does other things like populate an index or (in the above example) a Latin-English glossary, and so forth. I didn't do that here, because this might not be the approach you are looking for.

  • Thanks! This has exceptional application and learning potential. I look forward to learning from and developing a solution around this. – EngBIRD Jun 28 '15 at 1:01
  • @EngBIRD -- Cheers. Please ask if you want more details and so forth. – jon Jun 28 '15 at 1:26

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.