0

Problem: WYSIWYG documents used by majority of my colleagues; I know I have better content in my notes but I cannot share/present it time-efficiently for them, without confusing them with excessive inline comments. They are just my notes so I do not want to work them for publication quality. Inline comments (%...) are necessary in the output.

Goal. Prioritise textual content from inline comments (%...) where different subenvironments (%%... for start of one content; %$... possible better sign for typical inline comments).

  • I need to collaborate with non-LaTeX users. I am thinking how I can well print .pdf from my notes for the overview.
  • I need the comments too because they essential for the understanding.
  • I do not want to use any non-full LaTeX package for changing my way of writing notes. I love the full semantics, but my colleagues can get confused especially about inline comments.
  • Comments. I keep in Comments Sources, some Source codes and explanation. They are necessary because I have there many times hyperlinks which extend/visualise the case much further.

Ways for Visualisation in parsing full-LaTeX Semantics to them

  • Colorise/italize/makeSmaller inline comments (%...).
  • Separate double comment environment (%%...)
  • New environment in inline comments etc (%$...)
  • I think Tikz can be the tool here.

Example with dummy content

\section{1.1.2016 Bowel obstruction. Classification. DX. Diff DX}

%% Sources
% http://apps.who.int/iris/bitstream/10665/75146/1/9789241548441_eng.pdf#page=35
% dia.pdf#page=534
% liver 3.pdf

% Localisation of hernias
Bowel obstruction. 

Small bowel obstruction (SBO).
\begin{enumerate}

\item DX 

    Examination.
    Percussion. % liver border, has to do 
    Auscultation. 
    % 
    Prognosis of patient: % recommendations 

    % Serious. 
    % Cholecystitis with % fistula to skin. 
    % Cholecystectomy convential; bleeding postoperative (hematoma in abdominal cavity), ...

    %% Hypertension 
    % Level  Systolic Diastolic  
    % normal <120     <80 
    % pre    120-139  80-89 
    % I      140-159  90-99
    % II     >160    >=100

\end{enumerate}

\begin{enumerate}

\item Lorem

    Physics: 
    Diffusion, ultrafiltration, convection. 

\end{enumerate}

\begin{enumerate}

\item Procedure

     Lorem

\end{enumerate}

\section{19.5.2016}
% Lorem

\section{20.5.2016}
% Lorem

\section{23.5.2016}
% Lorem

\section{24.5.2016}
% Lorem

% Indications.
Treatment  
\begin{itemize}

    \item Definition. 

\end{itemize}


\section{25.5.2016}
% Masi

%% 26.5.-3.6. from 11-14
\section{26.5.2016}
% Masi

\section{27.5.2016}

Separate environments

  • verbatim. Too raw without prioritising content from inline comments.
  • minted. I think it cannot work well for the whole document.
  • listings. It is designed for source code, not for text and comments. So I think not the right tool here.

1. Shorten long links in inline comments

Etc input http://apps.who.int/iris/bitstream/10665/75146/1/9789241548441_eng.pdf#page=35. It would be nice to have output like who...eng.pdf#page=35 which the hyperlink on it. I think this is not possible to do without extra semantics.

I think this can be also be solved by making comments small and with smaller linespace.

2. Tables in inline comments starting as double comment mark (%%)

See the example for the input. I think Windows help-file (.h) way making a new document about tables with a link to the source coudl work here very well.

Review of UlrikeFischer's answer

I think if-else structure by design can have difficulties to work well. A systematic approach can work better: functions to bring specific characteristics. TODO functions.

  1. Test 1. Matching %% should not match %.*%. Data %\include{8.9.2015.tex} % Masi. Other test data % About 75\% efficiency of transplants work. This test data passed by 2nd edit of Ulrike.

Application of dual comment coloring (%.*%) overflows many semantics commands (\section, ...) if %% just before them.

\section{25.5.2016}
% Masi

%% 26.5.-3.6. from 11-14
\section{26.5.2016}
% Masi

\section{27.5.2016}

Expected output: 26.5.-3.6. from 11-14 in green, section 26.5.2016 in black*, and Masi in red. Output: all in green after %%

enter image description here

Incomplete evidence because the example above does not show it. TODO

  1. Insertion of pagebreaks causes complications. I think it may be related to tabs \t which is before the word Diffusion. Test data 2

    \begin{enumerate}
    
    \item Lorem
    
        Physics: 
        Diffusion, ultrafiltration, convection. 
    
    \end{enumerate}
    

Expected output is one liner: Physics: Diffusion, ultrafiltration, convection. Output

enter image description here

  1. Test data 3

    \begin{enumerate}
    
    \item Procedure
    
         Lorem
    
    \end{enumerate}
    

Expected output: word Procedure in black. Test passed after Ulrike's 3rd input.

  1. Test data 5

    \section{19.5.2016}
    % Lorem
    
    \section{20.5.2016}
    % Lorem
    
    \section{23.5.2016}
    % Lorem
    
    \section{24.5.2016}
    % Lorem
    

Expected output: 24.5.2016's comments are in red. Passed after Ulrike's 3rd input.

  1. Test case 6

    % Indications.
    Treatment  
    \begin{itemize}
    
        \item Definition. 
    
    \end{itemize}
    

Expected output: Indications in red, Treatment in black, and the dot of Definition in black. Output: Treatment in black, and the dot of Definition in red

enter image description here

  1. Test case 7: How to handle underscores/hashtags in inline comments?

Input

% http://apps.who.int/iris/bitstream/10665/75146/1/9789241548441_eng.pdf#page=35

Expected output: link in red without formatting. Solution

% http://tex.stackexchange.com/a/309617/13173
\catcode`\_=12 % disable function of underscores 
\catcode`\#=12 % disable function of hashtags 
  1. Test case 8: have URLs which have percentage signs

Input

% http://apps.who.int/%%%iris/bitstream/10665/75146/1/9789241548441_eng.pdf#page=35

Output http://apps.who.int/iris/bitstream/10665/75146/1/9789241548441_eng.pdf#page=35. Expected output ...%%%iris.... Solution: expand links before having them in inline comments. I think this feature is not critical.

  1. Test case 9: Prioritise more early inline comments in the same line

Input

% masi is lorem ipsun % this is less important but % even more less important`

Current output: masi is lorem ipsun this is less important but even more less important where is no prioritizing.

  1. Test case 10: include .tex files in the main document

Code

\include{8.9.2015} % this is a comment

Expected output: like text in the main document. Output: many errors. Something internal in \include probably causing it.


How Can you Print .pdf from .tex Notes with Visualised Inline Comments for Overview for non-LaTeX Users?

  • I don't really understand what you want to achieve. todonotes package? If the comments are essential for understanding, why are they comments? – Torbjørn T. May 14 '16 at 7:14
  • But you're asking how to make a PDF that includes the comments ... Or do you just want the source, verbatim? – Torbjørn T. May 14 '16 at 7:23
  • 5
    Masi, you manage to surprise me again and again with questions that make me think: What the heck is he trying to do? If i understand the question (would be the first time) this is a complete mixup betweeen Input/Output vs. You/collegues. This is like four corners of a square and i have no idea which edge shall communicate with which edge. – Johannes_B May 14 '16 at 7:42
  • 1
    So, you want to share a pdf file that contains the tex code as you wrote it but makes comments (starting with %) a bit smaller and colored? – Johannes_B May 14 '16 at 8:12
  • 2
    As a TeX neophyte (or worse) ... the issue here (it seems to me) is that %... comments are being used as "inline notes". They aren't really "comments" in the typical "coding" sense -- which are intended to REMOVE that material from text flow. Here, the "comments" add information necessary to the text flow. Solution: don't use TeX %... comments, but some other form of appropriate markup which retains that material in the text flow. No? – Dɑvïd May 14 '16 at 8:31
5

Well tikz is certainly not the tool. But you can naturally change the meaning of e.g. %. The problem is that it is not easy to confine the change "until the end of the current line". The best is imho to read the file line by line:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\begin{document}
\makeatletter
\newif\ifdoublecomment
\newif\ifincomment
\newcommand\commentstyle{\ifdoublecomment\color{green}\bfseries\else\color{red}\footnotesize\fi}

\begingroup
\catcode`\%=13
\def%{\@ifnextchar%{\doublecommenttrue\commentstyle\incommenttrue}{\commentstyle\incommenttrue}}

\newread\myread
\openin\myread=testinput.tex
\@whilesw\unless\ifeof\myread\fi{
\read\myread to \dataline
\dataline
\ifincomment\par\fi\color{black}\normalsize\normalfont\incommentfalse\doublecommentfalse}
\closein\myread

\endgroup
\end{document}

Testinput.tex:

Small bowel obstruction (SBO).
\begin{enumerate}

\item DX

    Examination.
    Percussion. % liver border, has to do
    Auscultation.
    %
    Prognosis of patient: % recommendations

    % Serious.
    % Cholecystitis with %fistula to skin.
    % Cholecystectomy convential; bleeding postoperative (hematoma in abdominal cavity), ...

    %% Hypertension
    % Level  Systolic Diastolic
    % normal <120     <80
    % pre    120-139  80-89
    % I      140-159  90-99
    % II     >160    >=100

\item blblbl
      blblblb
      bllblb
\end{enumerate}

Output

enter image description here

It is imho possible to make the links active (and shorter) with the help of e.g. xstring -- you only need to check if the line contains a http but you should be aware that while it is easy to setup such a simple case and to devise solutions for all your wishes the fine tuning and the actual implementation can be very time consuming.

  • 1
    I edited the definition to avoid that %.*% matches. If you use \include in the comments this naturally will now be executed, give a pagebreak and will not be read line by line, so the coloring will not work. As I wrote: fine tuning this sort of things can be very time consuming. – Ulrike Fischer May 14 '16 at 12:20
  • Test cases 2, 3 and 5 are not passed. I think the insertion of pagebreak causes some complications, see test case 2. I think bug in test case 2 is caused by reading tabs \t as pagebreak. – Léo Léopold Hertz 준영 May 14 '16 at 13:17
  • 1
    I inserted another conditional to avoid the \par if the previous line wasn't a comment. But I really don't want to spent the next week to adapt the code to your test files. So this was the last change I made ... – Ulrike Fischer May 14 '16 at 13:34
0

Not enough reputation here to comment, but I wanted to say that you can probably use something like Markdown or Pandoc.

If that's not enough, you can use a templating engine to set up everything in LaTeX, and write your notes in YAML or something. I used Jinja2 with Python to automatically generate my resumes. (https://github.com/masasin/resume)

  • No, thank you for these proposals! I have done many attempts on them, and Ulrike's answer is much much better at the moment than those two tools can ever provide. – Léo Léopold Hertz 준영 May 14 '16 at 11:58

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.