Skip to content

Instantly share code, notes, and snippets.

@wtsnjp
Created July 8, 2019 08:36
Show Gist options
  • Save wtsnjp/f5bc5780b2eaaf5cec09821573a1f377 to your computer and use it in GitHub Desktop.
Save wtsnjp/f5bc5780b2eaaf5cec09821573a1f377 to your computer and use it in GitHub Desktop.
%%
%% This is file 'notexcode.sty'.
%%
%% Copyright 2019 Takuto ASAKURA (wtsnjp)
%% GitHub: https://github.com/wtsnjp
%% Twitter: @wtsnjp
%%
%% This package is distributed under the MIT License.
%%
% -------------------------------------------------- declarations
\RequirePackage{expl3}
\ProvidesExplPackage {notexcode} {2019/07/08} {0.1.0}
{Let's stop writing TeX macro language unconsciously}
% -------------------------------------------------- messages
\msg_new:nnn { notexcode } { primitive-found }
{
There~is~a~TeX~primitive~\msg_line_context: :~\exp_not:N #1
}
% -------------------------------------------------- imprementation
\cs_new:Npn \ntcd_notexcode:n #1
{
\tl_map_function:nN { #1 } \__ntcd_warn_if_primitive:N
\__ntcd_exec:n { #1 }
}
\cs_new:Npn \__ntcd_warn_if_primitive:N #1
{
\int_compare:nNnTF { \tl_count:n { #1 } } = { \c_one_int }
{
\token_if_primitive:NT #1
{ \msg_warning:nnn { notexcode } { primitive-found } { #1 } }
}
{ \tl_map_function:nN { #1 } \__ntcd_warn_if_primitive:N }
}
\cs_new:Npn \__ntcd_exec:n #1 { #1 }
% -------------------------------------------------- LaTeX2e interface
%% \notexcode { <code> }
\cs_new_eq:NN \notexcode \ntcd_notexcode:n
% vim: ft=expl3 nospell:
%% EOF
\documentclass{article}
\usepackage{notexcode}
\notexcode{\newcommand{\foo}{foo}}% LaTeX code
\notexcode{\def\bar{bar}}% TeX code
\begin{document}
Hello {\foo} and {\bar}!
\end{document}
@wtsnjp
Copy link
Author

wtsnjp commented Jul 8, 2019

Processing test.tex with

$ latex test.tex

will show you a warning message which looks like

Package notexcode Warning: There is a TeX primitive on line 5: \def

in your terminal and the log file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment