I am working on context-based log entries. Each time a selected (patched) macro is called, it should provide its contents along with a meaningful log entry.
"Meaningful" log entry defined:
The following context is given per custom log entry:
- section counter value
- section title
- page number
- file name/path
- line number
This is what I want:
<macro content> (<section counter value>:<section title>:<page number>:<file>:<line number>)
Problems
I have two problems I guess:
- Dealing with
\thetitlewhen one of these selected macros falls within a sectioning command itself. - Getting full value of expanded macro into log as string in case with
\myproductmacro.
How I have implemented "meaningful" log entries
\thetitleget section countertitlesec\@currentlabelnameget section titletitlesecprovides\def\@currentlabelnamefor nameref (I only tested this with straight classes, that is, classes with nobottomtitles)\thepageget page LaTeX\the\inputlinenoget line number LaTeX (refers to lineno in current file when using\input)max_print_line=10000intexmf.cnfto expand max chars per line in log output (irrelevant to this question, but relevant for people who might also want to implement custom logs)
Hopefully I have my facts straight above.
Problem 2 (almost working, typesets fine)
Sometimes my section titles contains macros. This could lead to expansion problems. Also, sometimes the section titles contain the very macro I am tracking, which makes it tricky to use \thetitle in the log entry e.g. \section{About \myproduct{monkey shampoo}} which should yield e.g. MacGyver.monkey shampoo (2:About MacGyver.monkey shampoo:[1]:test.tex:11).
\documentclass{article}
\usepackage{fontspec}% use xelatex
\usepackage{titlesec}% adds \thetitle and \@currentlabelname
\usepackage{currfile}% adds \currfilepath
% Define a couple commands to track
\newcommand\myapp[1]{\textit{#1}}
\newcommand\myproduct[1]{MacGyver.\textit{#1}}% Purposefully made this one contain more text that what is saved in #1
% The following is normally put into separate file as to modularize the application of patches
% Define a context macro as described
\makeatletter
\def\contextinfo{\thetitle:\@currentlabelname:[\thepage]:\currfilepath:\the\inputlineno}
\makeatother
% Apply Patches
\usepackage{regexpatch}
\xapptocmd{\myapp}{\typeout{ ==> #1 (\contextinfo)}}{}{}
\xapptocmd{\myproduct}{\typeout{ ==> #1 (\contextinfo)}}{}{}% <-- I'd rather show MacGyver.monkey shampoo, but unsure how best to implement
% Note: \typeout is always fully expanded due to \write %http://tex.stackexchange.com/a/60976/13552
\begin{document}
\section{Elephant}
\section{Monkey}
\subsection{Bonabo}
\myapp{listmonkeys}
\myproduct{monkey shampoo}
\end{document}
Log Output
See problem 2 above: How can I make "monkey shampoo" be "MacGyver.monkey shampoo" or maybe easier: MacGyver.\textit{monkey shampoo}
==> listmonkeys (2.1:Bonabo:[1]:test.tex:34)
==> monkey shampoo (2.1:Bonabo:[1]:test.tex:35)
Problem 1 (not working, does not typeset)
See Problem 1 above: How can I deal with the \thetitle, which is defined in titlesec by \gdef\thetitle{\csname the#1\endcsname}%?
\documentclass{article}
\usepackage{fontspec}% use xelatex
\usepackage{titlesec}% adds \thetitle and \@currentlabelname
\usepackage{currfile}% adds \currfilepath
% Define a couple commands to track
\newcommand\myapp[1]{\textit{#1}}
\newcommand\myproduct[1]{MacGyver.\textit{#1}}% Purposefully made this one contain more text that what is saved in #1
% The following is normally put into separate file as to modularize the application of patches
% Define a context macro as described
\makeatletter
\def\contextinfo{\thetitle:\@currentlabelname:[\thepage]:\currfilepath:\the\inputlineno}
\makeatother
% Apply Patches
\usepackage{regexpatch}
\xapptocmd{\myapp}{\typeout{ ==> #1 (\contextinfo)}}{}{}
\xapptocmd{\myproduct}{\typeout{ ==> #1 (\contextinfo)}}{}{}% <-- I'd rather show MacGyver.monkey shampoo, but unsure how best to implement
% Note: \typeout is always fully expanded due to \write %http://tex.stackexchange.com/a/60976/13552
\begin{document}
\section{Elephant \myapp{watcher}}% probably \thetitle has not been set yet, causing error
\section{Monkey \myproduct{monkey shampoo}}
\subsection{Bonabo}
\end{document}
Log Output
! TeX capacity exceeded, sorry [input stack size=5000].

\@currentlabelnamethat causes the stuff to fail somehow – Jun 22 '16 at 14:07\thetitle. They are both defined under\def\ttl@straight@i#1[#2]%intitlesec.sty– Jonathan Komar Jun 22 '16 at 14:08