@forelse($explanations as $explanation)
@if($explanation->title)
{{ $explanation->title }}
@endif
@php
$cleanContent = $explanation->content;
// Process block math $$...$$
$cleanContent = preg_replace_callback('/\$\$([\s\S]+?)\$\$/', function($matches) {
// Strip raw newlines and
tags within the math
$math = preg_replace('/
|\n|\r/i', ' ', $matches[1]);
return '$$' . $math . '$$';
}, $cleanContent);
// Process inline math $...$ and upgrade to display math $$ \displaystyle{...} $$
$cleanContent = preg_replace_callback('/\$([\s\S]+?)\$/', function($matches) {
$math = preg_replace('/
|\n|\r/i', ' ', $matches[1]);
return '$$\displaystyle{' . $math . '}$$';
}, $cleanContent);
@endphp
{!! $cleanContent !!}
@empty
No explanations saved yet. Try adding one on the left!
@endforelse